If you don’t care about the aspect of the diet (i.e. you want the image to fit to a specific size), here is a simplified answer
// for jpg function resize_imagejpg($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefromjpeg($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; } // for png function resize_imagepng($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefrompng($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; } // for gif function resize_imagegif($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefromgif($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; }
Now let's handle the download part. At the first stage, upload the file to the desired directory. Then, one of the above functions is called based on the file type (jpg, png or gif) and passes the absolute path of your downloaded file, as shown below:
// jpg change the dimension 750, 450 to your desired values $img = resize_imagejpg('path/image.jpg', 750, 450);
Return value $img - resource object. We can save the new location or redefine the original, as shown below:
// again for jpg imagejpeg($img, 'path/newimage.jpg');
Hope this helps someone. Check out these links for more detailed resizing of Imagick :: resizeImage and imagejpeg ()