note 36817 deleted from function.imagecopyresized by aidan

From: Date: Mon, 04 Oct 2004 09:38:57 +0000
Subject: note 36817 deleted from function.imagecopyresized by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77909@lists.php.net to get a copy of this message
Note Submitter: matheus at slacklife dot com dot br ---- //I caught the function of another user of php.net and //recoding it stops being better and to get better resulted, //left this function that follows below: // Image Resize 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") && ($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 (!imagecopyresized($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 (#77909) next »