Recommend this page to a friend! |
All requests | > | i want to resize image class | > | Request new recommendation | > | Featured requests | > | No recommendations |
by Keith G - 6 years ago (2018-05-01)
+2 | i want resize image code whatever image is height or width. |
1. by riccardo castagna - 6 years ago (2018-05-29) Reply
may be this will be usefull for your problem : the php working code with jpeg is: <?php $source_image = imagecreatefromjpeg("osaka.jpg"); $source_imagex = imagesx($source_image); $source_imagey = imagesy($source_image); $dest_imagex = 300; $dest_imagey = 200; $dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey); imagecopyresampled($dest_image, $source_image, 0, 0, 0, 0, $dest_imagex, $dest_imagey, $source_imagex, $source_imagey);
imagejpeg($dest_image,NULL,80); ?> This example scales and compress a jpeg image but you will be able to add others php functions like (imagecreatefromgif() and imagegif() ) for gif images for example and (imagecreatefrompng() and imagepng() ) ... etc .. etc.
2. by riccardo castagna - 6 years ago (2018-05-29) in reply to comment 1 by riccardo castagna Comment
for whatever image you can do in this way and you in this way you will be able to compress the image and also convert into webp (for exaple) :
$filename = "./an_image.png";
$size = getimagesize($filename); list($width, $height) = $size; if (!file_exists($fileWebP)){ switch ($size['mime']) {
case "image/gif":
$im = imagecreatefromgif($filename);
break;
case "image/jpeg":
$im = imagecreatefromjpeg($filename);
break;
case "image/png":
$im = imagecreatefrompng($filename);
break;
case "image/bmp":
$im = imagecreatefrombmp($filename);
break;
} $source_imagex = imagesx($im); $source_imagey = imagesy($im); $dest_imagex = 300; $dest_imagey = 150; $dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey); imagecopyresampled($dest_image, $im, 0, 0, 0, 0, $dest_imagex, $dest_imagey, $source_imagex, $source_imagey); $fileWebP = "./newimage.webp"; imagewebp($dest_image, $fileWebP, 60);
0 | by riccardo castagna 165 - 6 years ago (2018-06-10) Comment This package solve the problem of resizing image and also it is possible to convert the original image source file into a new lighter webp image file or into other format. And also it is possible to compress the image file. It is possible to set the transparency. In my example there is also explained a method to load faster the web page if you have to load, for example, a lot of images in only one page. A load event listener load at the beginning only three images and a scroll event listener defer the others. |
+1 | by zinsou A.A.E.Moïse 5850 - 6 years ago (2018-05-04) Comment there are severals packages in the repository but this is one of the best i have tried and which i used in many of my packages for this purpose...Just try it and let us know. |
Recommend package | |
|