note 94221 added to function.imagecopyresampled
| From: | michael at heymichael dot com | Date: | Fri, 23 Oct 2009 05:08:01 +0000 |
| Subject: | note 94221 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162002@lists.php.net to get a copy of this message | ||
imagecopyresampled() works amazingly well, but here is something NOT to try with it:
The resize routine I wrote looks for pixel widths, and resizes images based on the notion that if
their widths and heights are too big, so are their byte sizes. It worked out well at first.
But when I saw huge byte-size images slipping through beneath my 1000px-wide benchmark, I figured
I'd subject the smaller-width images to resizing if their filesize() exceeded 100K.
The idea was that I'd "resize" them keeping their original widths and heights (i.e.
in (1) below, $newW = $oldW, $newH = $oldH), and letting the "75" at (2) below reduce the
byte size.
DON'T try that. imagecopyresampled() will lock up the server trying to resize an 800px-wide
image to a "new" width of 800px. (I caught that on my Windows server before ever putting
it on the destination Linux server, so take that with a grain of salt.)
I got around it by making $newW = ($picW * 0.99), etc. You get the byte-size reduction you want
without locking up.
(1) imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newW, $newH, $picW, $picH);
(2) imagejpeg($image_p, $theFile, 75);
----
Server IP: 64.71.164.2
Probable Submitter: 74.242.163.92
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/94221
Del: integrated -- https://master.php.net/note/delete/94221/integrated
Del: useless -- https://master.php.net/note/delete/94221/useless
Del: bad code -- https://master.php.net/note/delete/94221/bad+code
Del: spam -- https://master.php.net/note/delete/94221/spam
Del: non-english -- https://master.php.net/note/delete/94221/non-english
Del: in docs -- https://master.php.net/note/delete/94221/in+docs
Del: other reasons-- https://master.php.net/note/delete/94221
Reject -- https://master.php.net/note/reject/94221
Search -- https://master.php.net/manage/user-notes.php