Skip to content

Commit 997c9ed

Browse files
Merge pull request #6 from fahadadeel/master
Aspose.Imaging Java for PHP Examples
2 parents 425a336 + 0e09f39 commit 997c9ed

File tree

87 files changed

+1755
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1755
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Aspose.Imaging Java for PHP
2+
Aspose Imaging Java for PHP is a PHP project that demonstrates / provides the Aspose.Imaging for Java API usage examples in PHP by using PHP/JAVA Bridge.
3+
4+
You will need to configure PHP/Java Bridge before using any of the Aspose provided Java APIs in PHP e.g Aspose.Imaging, Aspose.Cells and Aspose.Slides etc.
5+
6+
For the configuration/setup of PHP/Java Bridge, please see:
7+
8+
http://php-java-bridge.sourceforge.net/pjb/index.php
9+
10+
To download Aspose.Imaging for Java API to be used with these examples through PHP/Java Bridge
11+
Please navigate to:
12+
13+
http://www.aspose.com/community/files/72/java-components/aspose.imaging-for-java/
14+
15+
For most complete documentation of the project, check Aspose.Imaging Java for PHP confluence wiki link:
16+
17+
http://www.aspose.com/docs/display/imagingjava/2.+Aspose.Imaging+Java+For+PHP
18+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "asposeimaging/aspose_imaging_java_for_php",
3+
"description": "Aspose Imaging Java Examples for PHP Developers. Helps you understand how to use Aspose.Imaging Java classes in your PHP Projects.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Fahad Adeel",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"require": {
14+
"php": ">=5.3.0"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"Aspose\\Imaging\\": "src/aspose/imaging"
19+
}
20+
}
21+
}

Plugins/Aspose_Imaging_Java_for_PHP/composer.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace Aspose\Imaging\ConvertingMetafilestoOtherImageFormats;
3+
4+
use com\aspose\imaging\fileformats\metafile\EmfMetafileImage as EmfMetafileImage;
5+
use com\aspose\imaging\imageoptions\BmpOptions as BmpOptions;
6+
use com\aspose\imaging\imageoptions\JpegOptions as JpegOptions;
7+
use com\aspose\imaging\imageoptions\PngOptions as PngOptions;
8+
use com\aspose\imaging\imageoptions\GifOptions as GifOptions;
9+
use com\aspose\imaging\imageoptions\TiffOptions as TiffOptions;
10+
use com\aspose\imaging\fileformats\tiff\enums\TiffExpectedFormat as TiffExpectedFormat;
11+
12+
class ConvertMetafileToOtherFormats{
13+
14+
public static function run($dataDir=null){
15+
16+
# Load a Metafile in an instance of EmfMetafileImage class
17+
$metafile = new EmfMetafileImage($dataDir . "sample1.emf");
18+
19+
# Save EMF to BMP using BmpOptions object
20+
$metafile->save($dataDir . "EmfToBmp.bmp", new BmpOptions());
21+
22+
# Save EMF to JPG using JpegOptions object
23+
$metafile->save($dataDir . "EmfToJpg.jpg", new JpegOptions());
24+
25+
# Save EMF to PNG using PngOptions object
26+
$metafile->save($dataDir . "EmfToPng.png", new PngOptions());
27+
28+
# Save EMF to GIF using GifOptions object
29+
$metafile->save($dataDir . "EmfToGif.gif", new GifOptions());
30+
31+
# Save EMF to TIFF using TiffOptions object with default settings
32+
$tiffExpectedFormat=new TiffExpectedFormat();
33+
$metafile->save($dataDir . "EmfToTiff.tiff", new TiffOptions($tiffExpectedFormat->Default));
34+
35+
# Display Status.
36+
print "Converted EMF to BMP, JPEG, PNG, GIF and TIFF formats successfully!".PHP_EOL;
37+
}
38+
39+
}
40+
41+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace Aspose\Imaging\ConvertingMetafilestoOtherImageFormats;
3+
4+
use com\aspose\imaging\Image as Image;
5+
use com\aspose\imaging\Rectangle as Rectangle;
6+
class CropMetafile{
7+
8+
public static function run($dataDir=null){
9+
10+
# Load an existing image in an instance of Image class
11+
$image=new Image();
12+
$image = $image->load($dataDir . "sample1.emf");
13+
14+
# Create an instance of Rectangle class with desired size
15+
$rectangle = new Rectangle(10, 10, 100, 100);
16+
17+
# Perform the crop operation on object of Rectangle class
18+
$image->crop($rectangle);
19+
20+
# Save the result in PNG format
21+
$image->save($dataDir . "CropMetafile.png");
22+
23+
# Display Status.
24+
print "Saved crop emf image to PNG successfully!".PHP_EOL;
25+
}
26+
27+
}
28+
?>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
namespace Aspose\Imaging\DrawingImages;
3+
4+
use com\aspose\imaging\imageoptions\BmpOptions as BmpOptions;
5+
use com\aspose\imaging\sources\StreamSource as StreamSource;
6+
use com\aspose\imaging\Image as Image;
7+
use com\aspose\imaging\Color as Color;
8+
use com\aspose\imaging\Pen as Pen;
9+
use com\aspose\imaging\Graphics as Graphics;
10+
11+
use java\io\ByteArrayInputStream as ByteArrayInputStream;
12+
class DrawingArc{
13+
14+
public static function run($dataDir=null){
15+
16+
# Create an instance of BmpOptions and set its various properties
17+
$create_options = new BmpOptions();
18+
$create_options->setBitsPerPixel(32);
19+
20+
# Define the source property for the instance of BmpOptions
21+
$ary=array();
22+
$create_options->setSource(new StreamSource(new ByteArrayInputStream($ary)));
23+
24+
# Create an instance of Image
25+
$image=new Image();
26+
$image = $image->create($create_options,100,100);
27+
28+
# Create an instance of Color
29+
$color = new Color();
30+
31+
# Create an instance of Pen
32+
$pen = new Pen();
33+
34+
# Create and initialize an instance of Graphics class
35+
$graphic = new Graphics($image);
36+
37+
# Clear the image surface with Yellow color
38+
$graphic->clear($color->getYellow());
39+
40+
# Draw arc to screen.
41+
$graphic->drawArc(new Pen($color->getBlack()), 0, 0, 100, 200, 45, 270);
42+
43+
# Save all changes.
44+
$image->save($dataDir . "DrawArcExample.bmp");
45+
print "Arc have been drawn in image successfully!".PHP_EOL;
46+
}
47+
}
48+
?>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
namespace Aspose\Imaging\DrawingImages;
3+
4+
use com\aspose\imaging\imageoptions\BmpOptions as BmpOptions;
5+
use com\aspose\imaging\sources\StreamSource as StreamSource;
6+
use com\aspose\imaging\Image as Image;
7+
use com\aspose\imaging\Color as Color;
8+
use com\aspose\imaging\Pen as Pen;
9+
use com\aspose\imaging\Graphics as Graphics;
10+
use com\aspose\imaging\brushes\SolidBrush as SolidBrush;
11+
use com\aspose\imaging\Rectangle as Rectangle;
12+
13+
use java\io\ByteArrayInputStream as ByteArrayInputStream;
14+
class DrawingEllipse{
15+
16+
public static function run($dataDir=null){
17+
18+
# Create an instance of BmpOptions and set its various properties
19+
$create_options = new BmpOptions();
20+
$create_options->setBitsPerPixel(32);
21+
22+
# Define the source property for the instance of BmpOptions
23+
$ary=array();
24+
$create_options->setSource(new StreamSource(new ByteArrayInputStream($ary)));
25+
26+
# Create an instance of Image
27+
$image=new Image();
28+
$image = $image->create($create_options,100,100);
29+
30+
# Create an instance of Color
31+
$color = new Color();
32+
33+
# Create an instance of Pen
34+
$pen = new Pen();
35+
36+
# Create and initialize an instance of Graphics class
37+
$graphic = new Graphics($image);
38+
39+
# Clear the image surface with Yellow color
40+
$graphic->clear($color->getYellow());
41+
42+
$solid_brush = new SolidBrush();
43+
$rectangle = new Rectangle();
44+
45+
# Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle
46+
$graphic->drawEllipse(new Pen($color->getRed()), new Rectangle(30, 10, 40, 80));
47+
48+
# Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle
49+
$graphic->drawEllipse(new Pen(new SolidBrush($color->getBlue())), new Rectangle(10, 30, 80, 40));
50+
51+
# Save all changes.
52+
$image->save($dataDir . "DrawEllipseExample.bmp");
53+
54+
print "Ellipse have been drawn in image successfully!".PHP_EOL;
55+
}
56+
57+
}
58+
59+
?>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Aspose\Imaging\DrawingImages;
3+
4+
use com\aspose\imaging\imageoptions\BmpOptions as BmpOptions;
5+
use com\aspose\imaging\sources\FileCreateSource as FileCreateSource;
6+
use com\aspose\imaging\Image as Image;
7+
use com\aspose\imaging\Color as Color;
8+
9+
class DrawingImagesUsingCoreFunctionality{
10+
11+
public static function run($dataDir=null){
12+
13+
# Create an instance of BmpOptions and set its various properties
14+
$create_options = new BmpOptions();
15+
$create_options->setBitsPerPixel(24);
16+
17+
# Create an instance of FileCreateSource and assign it to Source property
18+
$fileCreateSource=new FileCreateSource();
19+
$create_options->setSource(new FileCreateSource($dataDir . "sample.bmp",false));
20+
21+
# Create an instance of RasterImage
22+
$image=new Image();
23+
$raster_image = $image->create($create_options,500,500);
24+
25+
# Get the pixels of the image by specifying the area as image boundary
26+
$pixels = $raster_image->loadPixels($raster_image->getBounds());
27+
28+
$index = 0;
29+
while ($index < sizeof($pixels)) {
30+
# Set the indexed pixel color to yellow
31+
$color = new Color();
32+
$pixels[$index] = $color->getYellow();
33+
$index += 1;
34+
}
35+
$raster_image->savePixels($raster_image->getBounds(), $pixels);
36+
37+
# save all changes
38+
$raster_image->save();
39+
40+
print "Draw Images Using Core Functionality.".PHP_EOL;
41+
}
42+
}
43+
?>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Aspose\Imaging\DrawingImages;
3+
4+
use com\aspose\imaging\imageoptions\BmpOptions as BmpOptions;
5+
use com\aspose\imaging\sources\FileCreateSource as FileCreateSource;
6+
use com\aspose\imaging\Image as Image;
7+
use com\aspose\imaging\Graphics as Graphics;
8+
use com\aspose\imaging\Color as Color;
9+
use com\aspose\imaging\Pen as Pen;
10+
use com\aspose\imaging\Rectangle as Rectangle;
11+
12+
class DrawingImagesUsingGraphics{
13+
14+
public static function run($dataDir=null){
15+
16+
17+
# Create an instance of BmpOptions and set its various properties
18+
$create_options = new BmpOptions();
19+
$create_options->setBitsPerPixel(24);
20+
21+
# Create an instance of FileCreateSource and assign it to Source property
22+
$create_options->setSource(new FileCreateSource($dataDir . "DrawingImageUsingGraphics.bmp",false));
23+
24+
# Create an instance of Image
25+
$image=new Image();
26+
$image = $image->create($create_options,500,500);
27+
28+
# Create and initialize an instance of Graphics
29+
$graphics = new Graphics($image);
30+
31+
# Clear the image surface with white color
32+
$color=new Color();
33+
$graphics->clear($color->getWhite());
34+
35+
# Create and initialize a Pen object with blue color
36+
$pen = new Pen($color->getBlue());
37+
38+
# Draw Ellipse by defining the bounding rectangle of width 150 and height 100
39+
$graphics->drawEllipse($pen, new Rectangle(10, 10, 150, 100));
40+
41+
# save all changes
42+
$image->save();
43+
print "Created image using graphics.".PHP_EOL;
44+
}
45+
}

0 commit comments

Comments
 (0)