Optimized File Handling

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
floatint
Posts: 1
Joined: 2015-04-08T04:57:24-07:00
Authentication code: 6789

Optimized File Handling

Post by floatint »

Hello,

I'm using the PHP API Imagick. I'm not able to use the command line so I solely rely on the object oriented approach, which is nice but I'm not really sure about what is best performance wise.

One Example: if I had a loop that cuts an image in half and converts every half from png to jpg. At a point in my script I'll use $image->cropImage( $width , $height , $x , $y ); and after that the $image object only contains one half of the picture. Now my approach would be to save this image to a file and read it in later when I have to use it ($half_image = new Imagick('path to image'))) but with a lot of files that will be many read/write operations which can't be good und just doesn't feel right.
So it might be better to save the resulting halfs of the image in objects or better clone the original object beforehand and perform the operations afterwards?

Another example is compression: i read a file into an imagic object and set the (jpg) compression to let's say 1. Now I want to compare this image with its original. Would this be possible without saving the object with $image->writeImage($compress_src) and then $compressed_image = new Imagick(compress_src)? It feels kind of weird to write and then read again, but I guess the compression only happens when actually writing it to the filesystem. What I need is some kind of "simulateWrite" to an object is this somehow possible?

I hope you got my point.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Optimized File Handling

Post by Bonzo »

I would guess you will have to do some tests.

In a project I was working on using exec() I was surprised to find it was quicker to write and read an image as apposed to keeping it in the memory!
babybo
Posts: 1
Joined: 2015-04-14T03:52:09-07:00
Authentication code: 6789

Re: Optimized File Handling

Post by babybo »

I use PHP Imagick to generate invoices, using lots of read and write operations (additional images etc). I realized that best optimization was move script-engine to linux system, same script generates much much faster than on Windows, even on slower machine.
Najciekawsze gotowe projekty domów jednorodzinnych w serwisie Galerii Domów
Post Reply