I\'m wanting to write some PHP code which automatically resizes any image uploaded via a form to 147x147px, but I have no idea how to go about it (I\'m a relative PHP novice
private function getTempImage($url, $tempName){
$tempPath = 'tempFilePath' . $tempName . '.png';
$source_image = imagecreatefrompng($url); // check type depending on your necessities.
$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);
$dest_imagex = 861; // My default value
$dest_imagey = 96; // My default value
$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, $tempPath, 100);
return $tempPath;
}
This is an adapted solution based on this great explanation. This guy made a step by step explanation. Hope all enjoy it.