Example of a PHP function to resize an image

Check an example of how you can resize an image with PHP ...

Home Programming Examples PHP Examples → Example of a PHP function to resize an image
example of a php function to resize an image


function resize($im, $dst_width, $dst_height)
{
   $width = imagesx($im);
   $height = imagesy($im);

   $newImg = imagecreatetruecolor($dst_width, $dst_height);

   $white = imagecolorallocate($newImg, 255, 255, 255);
   imagefill($newImg,0,0,$white);
   
   imagecopyresampled($newImg, $im, 0, 0, 0, 0, $dst_width, $dst_height, $width, $height);

   return $newImg;
}

$image   = ImageCreateFromJpeg($uploaded_file);

$tn = resize($image, $modwidth, $modheight);

imagejpeg($tn, $save_file_name,95);
      
      



See More PHP ExamplesHire Me For A Project






 
Connect with meLinkedIn ProfileFacebook Profile


2024 © SofiaCoder.com
×

Programming ExamplesPHP ExamplesMySQL ExamplesJavaScript ExamplesHTML ExamplesCSS ExamplesNode.js ExamplesOther Home PageSofia Coder LinkedIn ProfileSofia Coder Facebook Profile