
Example of a PHP function to resize an image
Navigation
- Home ⟶ Programming Examples ⟶ PHP Examples ⟶ 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);
Discover more PHP Examples & Tutorials
PHP examples and tutorials
Example of searching XML file with PHP and XPath
Sanitizing the user input with the PHP filter_var function
May 4,2023