note 86818 deleted from function.imagecopyresampled by danbrown

From: Date: Wed, 05 Nov 2008 14:45:10 +0000
Subject: note 86818 deleted from function.imagecopyresampled by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146162@lists.php.net to get a copy of this message
Note Submitter: tim at leethost dot com ---- <?php function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality=2.33) { // Author: Tim Eckel - Date: 11/04/08 - Version: 1.2 - Project: FreeRingers.net - Freely distributable - These comments must remain. // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled. // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled". // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size. // // New in v1.2: 2 to 5 times faster when enlarging (v1.1 was slower than default imagecopyresampled when enlarging). // New in v1.2: Never slower than default imagecopyresampled function (v1.1 could be slower than default imagecopyresampled). // New in v1.2: Default quality of 2.33 reduces sizing artifacts that could happen with v1.1 (highly suggested: don't change this value). // New in v1.2: Automatically selects proper method to scale image for best quality and highest speed. if (empty($src_image) || empty($dst_image) || $quality < 1) { return false; } $scale = ($src_w / $dst_w + $src_h / $dst_h) / 2; if ($dst_w == $src_w && $dst_h == $src_h) imagecopy ($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h); elseif ($scale >= $quality) { $temp = imagecreatetruecolor ($dst_w * $quality + 1, $dst_h * $quality + 1); imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h); imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality); imagedestroy ($temp); } elseif ($scale == 1) imagecopyresized ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); elseif ($scale > 1 / $quality) imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); else { $temp = imagecreatetruecolor ($src_w * $quality, $src_h * $quality); imagecopyresampled ($temp, $src_image, 0, 0, $src_x, $src_y, $src_w * $quality, $src_h * $quality, $src_w, $src_h); imagecopyresized ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w + 1, $dst_h + 1, $src_w * $quality, $src_h * $quality); imagedestroy ($temp); } return true; } ?>

« previous php.notes (#146162) next »