Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
PHP Script - Resize JPG
Anyone know of a good PHP script that is able to resize a JPEG?
I found a couple of popular ones, popular because they keep showing up in searches, but they either corrupt the image every so often or result in crummy quality.
I found a couple of popular ones, popular because they keep showing up in searches, but they either corrupt the image every so often or result in crummy quality.
Posted: Wednesday, 16 May 2007 at 8:02PM
0
Comments
Posted: Wednesday, 16 May 2007 at 10:24PM
Have u tried as well. If yes then time to roll ur own. U just want to resize a jpg file thats it. nothing more.
Use imagecopyresized function. Its straight forward and there is a image resize of jpeg example posted on php.net http://us2.php.net/manual/en/function.imagecopyresized.php
Also check imagecopyresampled. they have an example of resizing via max width, or max height.
this is ur best route. lot of people have posted code in the comments. They have exactly what ur looking for.
Since its jpeg u will have to use imagecreatetruecolor to maintain quality
From Comments
<? function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { // 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 using the default quality setting. // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable. // // Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5. // 1 = Up to 600 times faster. Poor results, just uses imagecopyresized but removes black edges. // 2 = Up to 95 times faster. Images may appear too sharp, some people may prefer it. // 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled. // 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images. // 5 = No speedup. Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled. if (empty($src_image) || empty($dst_image)) { return false; } if ($quality <= 1) { $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); imagedestroy ($temp); } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { $tmp_w = $dst_w * $quality; $tmp_h = $dst_h * $quality; $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); imagedestroy ($temp); } else { imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } return true; } ?>
Strange they didn't show up in my search.
Posted: Thursday, 17 May 2007 at 9:12AM
Well u got one that worked for u right.
thats good. Now u can start working on a Gallery extension for Vanilla called Wanilla :P