Jump to content

Recommended Posts

Hello,

 

I have a PHP script that loops through a potentially large number of JPG images - it must read the width and height, and rotate each one by 90 degrees. There may be a couple thousand images in this loop, and each image is a photo of good quality, 3+ MB in size.

 

All the PHP timeout and memory use settings have been adjusted properly to accommodate this script. However, it does hang quite frequently and I'm thinking it may be due to the memory required for such a task. I'm trying my best to clean up all my variables and objects on each iteration, but it doesn't seem to free all the memory it should. I've checked memory_get_usage() etc. which seems to confirm this (although I think I remember reading somewhere that the value may be unreliable).

 

I'm thinking of writing a separate PHP script to handle the image rotation. On each iteration of the above loop I'd kick off this script via exec(). It would rotate the photo and then end.

 

These are my questions:

1) Is this considered a safe solution? I try to avoid using exec() if I can.

 

2) Is the solution unnecessary? Should one PHP script be able to handle such a loop without a problem?

 

Any help would be greatly appreciated.

 

Thanks, Brian

I dont dabble in this myself, but i had a little look for you and should be interesting for you;

 

http://theserverpages.com/php/manual/en/function.imagerotate.php

http://uk3.php.net/imagerotate

 

The comments on that page give lots of personal examples (i only scanned so i dont know the quality of the code). But it should give you some ideas, this is a quote:

If you need a rotate function, ask your provider to install JPEGTRAN on the machine your server runs on and use the command line tool from your php application.

JPEGTRAN is a *nix command, more information:

http://linux.about.com/library/cmd/blcmdl1_jpegtran.htm

are you sure its not a timeout problem (dues it fail after 30,60 , 90 seconds ?)

 

what about a script that resizes an image then uses a HTML Meta tag to redirect to the same page with a parameter that points to the next file

ie

rotatimg.php?ID=1

rotatimg.php?ID=2

rotatimg.php?ID=3

rotatimg.php?ID=4

...

this should clear the memory used and also stop any timeout issules

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.