Page 1 of 1
large files
Posted: 2010-07-13T16:06:49-07:00
by niccol
I have just started to use imagemagick so forgive me for asking things that may be obvious or have been answered before. I have had a llok around the forum and seen posts discussing dividing large images up etc. Anyway, here is my situation. I am uploading images and then scaling them via php with something like:
Code: Select all
$scaled = `convert $target_path -resize 800'x'800 $magic_path`;
So fairly simple. The problem is that this works fine for anything under about 1Mb but above that the resized image is just not created. Surely this doesn't count as an immense image?
So, what am I doing wrong and what things can I adjust to improve the situation / create more resources for the process.
Thanks
Nick
Re: large files
Posted: 2010-07-13T16:43:10-07:00
by anthony
niccol wrote:I am uploading images and then scaling them via php with something like:
Code: Select all
$scaled = `convert $target_path -resize 800'x'800 $magic_path`;
That is find and should work without problem for 1 Gb images, tough a couple of points.
You said it was working for smaller images, so you should be able to disregard PHP environment problems. That is not being about to actually run the command
- Why the backticks (`)? $scaled will never be assigned anything, especially not any errors
You have nothing in the convert command to print anything.
If you are wanting to capture errors include a 2>&1 ANYWHERE in the line (its for shell not for ImageMagick)
Check RubbleWeb which has many examples of calling IM from PHP scripts for alternative solutions.
- PHP may have set some memory limits which could result in that 1GB image forcing ImageMagick to go to disk caching. This is slow. PHP and/or the web server could also have time limits on script processing.
- Check the Web server Error log for problems or other things that could be going wrong.
It is very difficult to debug anything without some feedback. See my raw notes of PHP script error logging http://www.cit.griffith.edu.au/~anthony ... /php.hints
Perhaps 'Bonzo' (authour of RubbleWeb) can improve on those notes for better PHP feedback.
Re: large files
Posted: 2010-07-13T17:45:31-07:00
by snibgo
In addition, you should try a convert from the command line of a large image. If that works, it's either a script or PHP problem.
Re: large files
Posted: 2010-07-13T23:08:11-07:00
by niccol
Thanks guys. Nice to find a friendly, fast and helpful forum.
Yes, using imagemagick is all new to me so am on a learning curve!
1. The backticks. My understanding was that they emulated the exec command. Is that wrong?
2. Yes, there wasn't much feedback. I'll implement some php error handling. The odd thing here is that it is not slow. It is fast but just doesn't work. It works fine for a 800k image and takes some time. With a 1.2M image it just doesn't happen at all. I think the settings in php.ini are all right.
3. Yes, I will.
4. Yes, running it on shell is a good idea. I'll do that too.
As I say - thank you. When you step out of your comfort zone it is remarkable how some things that should be obvious just aren't

So thank you for putting me on the right track.
Nick
Re: large files
Posted: 2010-07-15T01:35:39-07:00
by niccol
Thanks for your help guys.
As it turned out I was making a newbie error. The issue appears to be with imbedded colorspaces rather than size (the large images had imbedded profiles and the small ones didn't). So, I am in the process of working out -profile. I was a bit surprised to find that with an imbedded profile the resize just doesn't happen. Is that right?
Anyway, any tips about how to cover all the bases about uploaded files with color profiles is gratefully accepted.
Thanks again
Re: large files
Posted: 2010-07-15T02:36:54-07:00
by snibgo
Resizing should work whether or not a file has an embedded profile. Do post the command and a sample file that is giving you problems.
Re: large files
Posted: 2010-07-18T14:50:18-07:00
by niccol
Thanks for all your help guys.
After wrestling with this and my hosting company it turns out that it was a weirdness in the server set up. All works fine now so thanks again
Nick
Re: large files
Posted: 2010-07-18T22:42:16-07:00
by anthony
niccol wrote:Thanks guys. Nice to find a friendly, fast and helpful forum.
You are quite welcome!
1. The backticks. My understanding was that they emulated the exec command. Is that wrong?
Almost but not quite.
Backticks, do run the command (feeding the string to a shell for parsing) but any output from STDOUT will be used to replace the backticks. It is really a substitution using command output.
Exec() on the other hand does NOT save the output but just pass it directory to the scripts own standard output, for PHP this is either a terminal, or as part of the web page! However Exec() should also allow you to run the command to capture stdout, stderr, and hopefully also let you give each argument string seperatally so as to avoid the need for an extra level of shell parsing.
That last is very important for security, as it means you have less to worry about random input strings 'cracking' your script because of shell parsing, and opening a security hole.
Perl Exec for example will let you call commands without invoking a shell. It has a whole Security FAQ about it. PHP on the otherhand does not seem to have this type of security level, whcih is strange considering its use in a security concious environment (web programming)
2. Yes, there wasn't much feedback. I'll implement some php error handling. The odd thing here is that it is not slow. It is fast but just doesn't work. It works fine for a 800k image and takes some time. With a 1.2M image it just doesn't happen at all. I think the settings in php.ini are all right.
Then try and get the error handling. If the command is shell parsed (backticks or exec() wise) then you can add 2>&1 to ask the shell to redirect stderr to stdout so that you can gather it in a variable (backticks) or to the web page (exec()). With that you could be able to figure out what is the problem..
DO let us know!