I am using php and I would like to a tool which help users cut their images using php. When a user uploads an image it is saved (for example as image1.png). I would like to know if there is a function which allows me to do it. What have I to do for example if I want to cut image1.png which has width and height 200px and make it have 100px width?
Thank you for your time!
yes it is possible, use the php GD library, be sure it's installed on your server.
see the imagecopyresampled coupled with imagecreatetruecolor functions for example
function setImage($image)
{
//Your Image
$this->imgSrc = $image;
//create image from the jpeg
this->myImage = imagecreatefromjpeg($this->imgSrc) or die("Error: Cannot find image!");
$this->cropWidth = 100;
$this->cropHeight = 200;
//getting the top left coordinate
$this->x = 0;
$this->y = 0;
}
function createThumb()
{
$this->thumb = imagecreatetruecolor(100, 200);
imagecopyresampled($this->thumb, $this->myImage, 0, 0,$this->x, $this->y, 100, 200, $this->100, $this->200);
}
function renderImage()
{
header('Content-type: image/jpeg');
imagejpeg($this->thumb);
imagedestroy($this->thumb);
}
$image = new cropImage;
$image->setImage($src);
$image->createThumb();
$image->renderImage();
Taken from http://www.talkphp.com/advanced-php-programming/1709-cropping-images-using-php.html
Edited to suit your particular needs. Visit the link for a comprehensive overview of PHP cropping.