Jump to content

Image resizing


Recommended Posts

we have a website running prestashop version:

 

the following code is in a class called annonce.php

 

$newwidth = 45;
$newheight = round($height * $newwidth / $width);
                        $tmp=imagecreatetruecolor($newwidth,$newheight);
                        $white = imagecolorallocate($tmp, 255, 255, 255);
         imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $white);


$newwidth1 = 400;
$newheight1 = round($height * $newwidth1 / $width);
                        $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
$white = imagecolorallocate($tmp1, 255, 255, 255);
         imagefilledrectangle($tmp1, 0, 0, $newwidth1, $newheight1, $white);

                        $newwidth2 = 430;
$newheight2 = round($height * $newwidth2 / $width);
                        $tmp2=imagecreatetruecolor($newwidth2,$newheight2);
$white = imagecolorallocate($tmp2, 255, 255, 255);
         imagefilledrectangle($tmp2, 0, 0, $newwidth2, $newheight2, $white);

                        $newwidth3 = 600;
$newheight3 = round($height * $newwidth3 / $width);
                        $tmp3=imagecreatetruecolor($newwidth3,$newheight3);
$white = imagecolorallocate($tmp3, 255, 255, 255);
         imagefilledrectangle($tmp3, 0, 0, $newwidth3, $newheight3, $white);

                        $newwidth4 = 183;
$newheight4 = round($height * $newwidth4 / $width);
                        $tmp4=imagecreatetruecolor($newwidth4,$newheight4);
$white = imagecolorallocate($tmp4, 255, 255, 255);
         imagefilledrectangle($tmp4, 0, 0, $newwidth4, $newheight4, $white);
                                
     imagecopyresampled($tmp, $src, (int)(($newwidth - $newwidth) / 2), (int)(($newheight - $newheight) / 2), 0, 0, $newwidth, $newheight, $width, $height);
                        imagecopyresampled($tmp1, $src, (int)(($newwidth1 - $newwidth1) / 2), (int)(($newheight1 - $newheight1) / 2), 0, 0, $newwidth1, $newheight1, $width, $height);
imagecopyresampled($tmp2, $src, (int)(($newwidth2 - $newwidth2) / 2), (int)(($newheight2 - $newheight2) / 2), 0, 0, $newwidth2, $newheight2, $width, $height);
imagecopyresampled($tmp3, $src, (int)(($newwidth3 - $newwidth3) / 2), (int)(($newheight3 - $newheight3) / 2), 0, 0, $newwidth3, $newheight3, $width, $height);
imagecopyresampled($tmp4, $src, (int)(($newwidth4 - $newwidth4) / 2), (int)(($newheight4 - $newheight4) / 2), 0, 0, $newwidth4, $newheight4, $width, $height);

                        $filename = "img/p/".$id_product."-".$id_image."-small.jpg"; //45/45
                        $filename1 = "img/p/".$id_product."-".$id_image."-medium.jpg"; //400/300
                        $filename2 = "img/p/".$id_product."-".$id_image."-large.jpg"; //430/400
                        $filename3 = "img/p/".$id_product."-".$id_image."-thickbox.jpg"; //600/600
                        $filename3 = "img/p/".$id_product."-".$id_image.".jpg"; //600/600
                        $filename4 = "img/p/".$id_product."-".$id_image."-home.jpg"; //183/156
                        
                        imagejpeg($tmp,$filename,100);
                        imagejpeg($tmp1,$filename1,100);
                        imagejpeg($tmp2,$filename2,100);
                        imagejpeg($tmp3,$filename3,100);
                        imagejpeg($tmp4,$filename4,100);
                        
                        imagedestroy($src);
                        imagedestroy($tmp);
                        imagedestroy($tmp1);
                        imagedestroy($tmp2);
                        imagedestroy($tmp3);
                        imagedestroy($tmp4);
 

It is used to resize an uploaded in different sizes to fit different views

This function code is not working

 

However when we upload an image from the backoffice, it is always correctly resized and placed in a white box and is not distorted.

 

can anyone please help?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...