This is the official PHP library for Image Manipulation. It is used for image manipulation functionalities like "Fit", "Fill", "Stretch", "Center". We have developed this image library in flexible and very user-friendly usage.
This library is developed in PHP. So, you need below requirement to proceed before the next steps.
-
PHP 7+
-
gd2 module should be enabled
Include Image "ImageManipulation.class.php" on your PHP file and create object for the class ImageManipulation
include("ImageManipulation.class.php");
$image=new ImageManipulation();
Below code is sample for how to use it. Please see methods and its functionalities below sections.
include("ImageManipulation.class.php");
$image=new ImageManipulation();
$image->ImageFrom("image.png");
$image->ImageType(ImageManipulation::IMAGE_TYPE_GIF);
$image->ImagePreserverTransparent(true);
$image->ImageManipulationAction(ImageManipulation::IMAGE_ACTION_FILL);
$image->ImageQuality(80);
$image->ImageResize(1000,1000);
$image->WorkSpaceColor(0,255,0);
$image->Output("../image.gif");
- file_from:
- Type:
String
- Type:
We should pass path of image into this method
$image->ImageFrom("image.png");
- file_type:
- Type:
String
- Default:
ImageManipulation::IMAGE_TYPE_JPG
- Type:
We may set the file type either PNG or GIF or JPG. This image library will convert the image type to this type.
$image->ImageType(ImageManipulation::IMAGE_TYPE_GIF);
Available options:
- ImageManipulation::IMAGE_TYPE_GIF
- ImageManipulation::IMAGE_TYPE_JPG
- ImageManipulation::IMAGE_TYPE_JPEG
- ImageManipulation::IMAGE_TYPE_PNG
- file_action:
- Type:
String
- Default:
ImageManipulation::IMAGE_ACTION_FILL
- Type:
We may set the image manipulation action here. This library has four actions. The output of the image will be based on this action selection
$image->ImageManipulationAction(ImageManipulation::IMAGE_ACTION_FILL);
Available options:
- ImageManipulation::IMAGE_ACTION_FIT
- ImageManipulation::IMAGE_ACTION_FILL
- ImageManipulation::IMAGE_ACTION_CENTER
- ImageManipulation::IMAGE_ACTION_STRETCH
-
file_resize_width:
- Type:
Integer
- Type:
-
file_resize_height:
- Type:
Integer
- Type:
This method used to specify the image width & height.
$image->ImageResize(1000,1000);
- file_quality:
- Type:
Integer
- Default:
90
for JPEG;8
for PNG
- Type:
We may also set image quality. Based on this image quality value, final image output will be generated. Please pass between 0 to 100 for JPEG; Pass 0 to 9 for PNG
Note: There is no quality option provided for GIF image output.
$image->ImageQuality(80);
- transparent:
- Type:
Boolean
- Default:
true
(For GIF <=> PNG )
- Type:
If you use final file type is PNG/GIF, the you may set this option to preserve the transparency of the image. Please set either TRUE or FALSE
$image->ImagePreserverTransparent(true);
-
red:
- Type:
Integer
- Default:
0
- Range:
0
to255
- Type:
-
green:
- Type:
Integer
- Default:
0
- Range:
0
to255
- Type:
-
blue:
- Type:
Integer
- Default:
0
- Range:
0
to255
- Type:
-
alpha:
- Type:
Integer
- Default:
127
- Range:
0
to127
- Type:
This is transparency color of PNG or GIF images.
$image->TransparencyColor(255,255,255,127);
-
red:
- Type:
Integer
- Default:
255
- Type:
-
green:
- Type:
Integer
- Default:
255
- Type:
-
blue:
- Type:
Integer
- Default:
255
- Type:
This is workspace color. You can see this color on ImageManipulation::IMAGE_ACTION_FIT.
$image->WorkSpaceColor(0,255,0);
This method will return the status of the functionality whether is going good or not.
$imageProcessStatus=$image->IsOkay();
echo "Process Status: ".(($imageProcessStatus[0])?"OK":"Error")."<br/>";
echo "Process Status Message: ".$imageProcessStatus[1];
- output (optional):
- Type:
String
- Default:
(empty)
- Type:
- file_overwrite (optional):
- Type:
Boolean
- Default:
true
- Type:
This will execute final process of this image library. It will automatically generate image based on all values given to this library and default values. If you want to show final output to browser, please leave this parameter to empty. Otherwise, please specify the path to write on disk.
In default, "file overwrite" is true. In that case, if file is already exist with output filename, then file will be overwritten. Otherwise, file will not overwrite but error will show in "IsOkay()".
$image->Output("../img1.gif"); // It will write image on disk
Or
$image->Output(); // It will show image on browser directly
Or
$image->Output("../img1.gif",false); // with "file_overwrite" = false