Wallogit.com
2017 © Pedro Peláez
A complete class for image manipulation
A complete solution for all kind of image operation., (*1)
Release 1.0.0, (*2)
Put package name in the composer.json file., (*3)
"require": {
........: ........,
........: ........,
"shahreare/imagesolution": "dev-master"
}
Then run composer update command. Then create the image object in your code with the image file name;, (*4)
$image = new \Imagesolution\Imagesolution('asset/logo.jpg');
There are several functionality this class can do., (*5)
getDim() function return an associative array with height and width of the image., (*6)
$val = $image->getDim(); echo $val['width']; // print width of the image echo $val['height']; // print height of the image
getFileType() function return the image type(extension) of the image., (*7)
echo $image->getFileType(); // print jpg/png/gif
To convert the image to png file from any file type use convertToPNG() function. This function will convert the image to png file with same name and same directory. Write permission is required on the directory to perform this operation., (*8)
$image->convertToPNG()
To convert the image to jpg file from any file type use convertToJPG() function. This function will convert the image to jpg file with same name and same directory. Write permission is required on the directory to perform this operation., (*9)
$image->convertToJPG()
To convert the image to gif file from any file type use convertToGIF() function. This function will convert the image to gif file with same name and same directory. Write permission is required on the directory to perform this operation., (*10)
$image->convertToGIF()
resize() function is for resizing the current image. This function needs two parameter width and height. By default maintaining aspect ratio is turned off. to maintain aspect ratio you have to add optional third parameter. In case of resize with aspect ratio, height and width will be calculated according to the image using given width and height as maximum value. Write permission is required on the directory to perform this operation., (*11)
$image->resize($width, $height); // without aspect ratio $image->resize($width, $height,1); // with aspect ratio
fitToWidth() function is a variation of the resize() function. in this function you have to put the width of the image as parameter. this function will calculate the height according to the new width and resize the image. Write permission is required on the directory to perform this operation., (*12)
$image->fitToWidth($width);
fitToHeight() is almost same as fitToWidth() function. As name suggest, instead of width it works on given height. Write permission is required on the directory to perform this operation., (*13)
$image->fitToHeight($height);
thumbnail() function is to make a small square image. By default it make 100x100 image. To use different length you can put your desire value in the parameter. Write permission is required on the directory to perform this operation., (*14)
$image->thumbnail(); $image->thumbnail($width);
To change the name of image use rename() function. this will change the name of the image. newfilename should be only name(no directory and no extention). this function keeps same location and image type. Write permission is required on the directory to perform this operation., (*15)
$image->rename($newfilename);
As name suggest, this function is to create a copy of the image with given name. this function copy the image and keeps in the same location. Write permission is required on the directory to perform this operation., (*16)
$image->copyImage($filename);
This is a work in progress. The class will be expanded from time to time., (*17)
MIT © A H M Reza Shahreare Khan, (*18)