note 30716 deleted from function.imagecopyresized by aidan

From: Date: Mon, 04 Oct 2004 09:39:44 +0000
Subject: note 30716 deleted from function.imagecopyresized by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77918@lists.php.net to get a copy of this message
Note Submitter: mitth at hotmail dot com ---- In addition to the problem where some users encounter black images as results of ImageCopyResampleBicubic , I suggest you initialize your destination image with imagecreatetruecolor - since we're wrapping around with jpg files anyways :) I use the following function to create thumbnails of any size -larger or smaller than the original image. Just for info - the machine uses a Redhat Linux, Apache/1.3.27 (Unix), PHP/4.3.1 with the GD 2.0. <?php function createthumb($IMAGE_SOURCE,$THUMB_X,$THUMB_Y,$OUTPUT_FILE){ $BACKUP_FILE = $OUTPUT_FILE . "_backup.jpg"; copy($IMAGE_SOURCE,$BACKUP_FILE); $IMAGE_PROPERTIES = GetImageSize($BACKUP_FILE); if (!$IMAGE_PROPERTIES[2] == 2) { return(0); } else { $SRC_IMAGE = ImageCreateFromJPEG($BACKUP_FILE); $SRC_X = ImageSX($SRC_IMAGE); $SRC_Y = ImageSY($SRC_IMAGE); if (($THUMB_Y == "0") AND ($THUMB_X == "0")) { return(0); } elseif ($THUMB_Y == "0") { $SCALEX = $THUMB_X/($SRC_X-1); $THUMB_Y = $SRC_Y*$SCALEX; } elseif ($THUMB_X == "0") { $SCALEY = $THUMB_Y/($SRC_Y-1); $THUMB_X = $SRC_X*$SCALEY; } $THUMB_X = (int)($THUMB_X); $THUMB_Y = (int)($THUMB_Y); $DEST_IMAGE = imagecreatetruecolor($THUMB_X,$THUMB_Y); unlink($BACKUP_FILE); if (!ImageCopyResampleBicubic($DEST_IMAGE, $SRC_IMAGE, 0, 0, 0, 0, $THUMB_X, $THUMB_Y, $SRC_X, $SRC_Y)) { imagedestroy($SRC_IMAGE); imagedestroy($DEST_IMAGE); return(0); } else { imagedestroy($SRC_IMAGE); if (ImageJPEG($DEST_IMAGE,$OUTPUT_FILE)) { imagedestroy($DEST_IMAGE); return(1); } imagedestroy($DEST_IMAGE); } return(0); } } # end createthumb ?>

« previous php.notes (#77918) next »