ServicesRapid Web DevelopmentAudits & ModernizationAI StrategyDigital Growth & SEO
MenuThe LabProductsInsightsProfile
Contact
PHP

Example of a PHP function to resize an image

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

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);

Need this implemented in your infrastructure?

Hire Me to Deploy