Re: [GD-DEVEL] Advanced image resize
| From: | ShadowRoze | Date: | Tue, 10 Jun 2008 16:58:08 +0000 |
| Subject: | Re: [GD-DEVEL] Advanced image resize | ||
| References: | 1 2 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-446@lists.php.net to get a copy of this message | ||
Pierre Joye skrev:
hi, On Tue, Jun 10, 2008 at 6:04 PM, ShadowRoze <roze@laun.se> wrote:I load the following types with the script utilizing the function: jpeg, gif, png. Not using ImageColorsForIndex results in having to use bitshifting instead.Hi, I would like to request that you add binary support for running Bicubic image resizing. Currently I only have a PHP code snippet, taking approx 20 seconds to resize a 2000x1000px image to 550x275px.For scaling images, is it really better than imagecopyresampled?I would like you to try speeding up this function, since 20 seconds is quite much, and the current functions does look quite bad.http://pastebin.com/m216c7c32 <-- the function I'm using.A couple of things that may help to speed up a bit your script: - if you load jpeg, drop the imagecolorforindex alltogether, jpeg are always truecolor (create two loops)
- don't allocate the color, simply calculate it once and use it with setpixel (0xAARRGGBB where AA goes from 0..127, other 0..255) save w*h function calls - truecolor image has no palette, no need to copy it (save a function call) - calculate ($w - $ow) (and its $h equivalent) outside the loops, php does not optimize this partAfter trying to implement all your suggestions the time required increased with 50% (ergo, to 30s).
And more generally, why don't you use a simpler algorithm for stretching images? Bicubic is good for scaling images (> 1.0x) but is not particullary good or fast for reducing images. A area weight implementation is fast and can give almost the best result (speed/quality ratio is good too). About adding new interpolations (besides copyresampled), it is in progress, I have working code already. The C API provides the following methods (classic and a couple of optimized versions): http://pierre.libgd.org/affine/api/files/src/gd-h.html#gdInterpolationMethodGuess I'll have to wait for that one then.
I'm also planing to add MMX/SSE2 version as well. These new features should be in php 5.3. Cheers,