Hi,
can anybody help me with resizing images. I have the following code that appears to work fine apart from when you start to use large images (some of the images i need to upload and resize are about 2500x1500 pixels and about 1mb in size).
When i try to resize one of these, the file outputed is simply a black square 🙁
Does PHP have a limitation on image size or is it my code?
any help would be much appreciated.
==============================================
function resize($IMAGE,$NEW_X,$NEW_Y,$OUTPUT_FILE)
{
$BACKUP_FILE = $OUTPUT_FILE . "_backup.jpg";
copy($IMAGE,$BACKUP_FILE);
$IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE);
if (!$IMAGE_PROPERTIES[2] == 2)
{
return(0);
}
else
{
//Create our source image
$SRC_IMAGE = ImageCreateFromJPEG($BACKUP_FILE);
//Keep the aspect ratio of the image
$SRC_X = ImageSX($SRC_IMAGE);
$SRC_Y = ImageSY($SRC_IMAGE);
$NEW_X = (int)($NEW_X);
$NEW_Y = (int)($NEW_Y);
//Create our desination image size
$DEST_IMAGE = imagecreatetruecolor($NEW_X, $NEW_Y);
//Destroy the backup image
unlink($BACKUP_FILE);
//resize the image
//$resize results = imagecopyresized($DEST_IMAGE, $SRC_IMAGE, 0, 0, 0, 0, $NEW_X, $NEW_Y, $SRC_X, $SRC_Y);
imagecopyresampled($DEST_IMAGE, $SRC_IMAGE, 0, 0, 0, 0, $NEW_X, $NEW_Y, $SRC_X, $SRC_Y);
echo "About to output resized image";
if (ImageJPEG($DEST_IMAGE,$OUTPUT_FILE))
{
return(1);
}
imagedestroy($SRC_IMAGE);
imagedestroy($DEST_IMAGE);
return(0);
}
}