AutoColor not working from PHP

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

AutoColor not working from PHP

Post by corbanb »

Hi all,

I am working on getting the autocolor, color2gray and toycamera scripts in place by using 'shell_exec' from PHP. I have been unable to get these scripts to work via 'shell_exec' due to an issue of being able to open the image. Everything is great when ran directly in the terminal on OSX 10.8 but throws the below error when being ran via PHP. I believe its an issue with the /tmp dir but wanted to get other thoughts.

Code: Select all

../bin/filters/autocolor -m recolor \xe2\x80\x93c separate /private/tmp/IMAGE-TMP-KiVjSs /private/tmp/IMAGE-TMP-KiVjSs, referer: http://example.com/
convert: unable to open image `–c': No such file or directory @ error/blob.c/OpenBlob/2646.
convert: no decode delegate for this image format `–c' @ error/constitute.c/ReadImage/552.
convert: no images defined `/private/tmp/autocolor_1_25621.mpc' @ error/convert.c/ConvertImageCommand/3106.
Would anyone know why PHP may be unable to open the image in the /tmp dir? Thanks!


**UPDATE** - The image being written to the /tmp dir from apace / mod_php is _www. Is there something I need to set for 'convert' and the fred scripts that will fix the permission issues?
Last edited by corbanb on 2013-09-29T20:32:48-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: AutoColor not working from PHP

Post by fmw42 »

Did you follow all the Pointers on my home page at http://www.fmwconcepts.com/imagemagick/index.php for use with PHP?

Perhaps PHP wants to use some other tmp directory and you do not have permission to use /tmp? You can point the script to some other tmp directory where you have permission and lots of space.

Is this your own server or a shared server? If the latter you may need to contact your ISP about using exec() and what permissions you need.

../bin/filters/autocolor -m recolor \xe2\x80\x93c separate /private/tmp/IMAGE-TMP-KiVjSs /private/tmp/IMAGE-TMP-KiVjSs, referer: http://example.com/
I do not understand the structure of your command. What do these red-highlighted items do? They are not arguments to my script and thus would confuse the script.
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

Re: AutoColor not working from PHP

Post by corbanb »

Thanks for the quick response Fred! I am not sure where that is coming from either. But I updated the script to get it right, followed the instructions in the PHP area on that page but still getting the errors below. Also this is running on my OSX 10.8 machine from a folder on the desktop for now. Any other thoughts?

Here is the script and the errors.

Code: Select all

<?php 
	
	$input = "og.png";
	$output = "og.png";
	$command = "./autocolor -m recolor –c separate $input $output";
	error_log($command);
	shell_exec($command);

 ?>

Code: Select all

# ERRORS
./autocolor -m recolor –c separate og.png og.png
convert: unable to open image `–c': No such file or directory @ error/blob.c/OpenBlob/2646.
convert: no decode delegate for this image format `–c' @ error/constitute.c/ReadImage/552.
convert: no images defined `/tmp/autocolor_1_27478.mpc' @ error/convert.c/ConvertImageCommand/3106.
Thanks for everything.
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

Re: AutoColor not working from PHP

Post by corbanb »

Looks like the -c flag was the issue. Seems to be working now when I remove that. Using IM 6.8.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: AutoColor not working from PHP

Post by fmw42 »

Something very odd is going on. When I run autocolor in any mode on IM 6.8.7.0 Q16 Mac OSX Snow Leopard, all I get is a grayscale result.

I do not see anything obvious, but I will take a closer look tomorrow and see what is going on.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: AutoColor not working from PHP

Post by fmw42 »

There seems to be a bug in either show: or -combine starting with 6.8.6.10. But that does not account for the -c option not working under PHP.

Can you try with exec() rather than shell_exec()?

Might you have some bad invisible character in your command when using -c separate? Does it happen with -c together?
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

Re: AutoColor not working from PHP

Post by corbanb »

Shoot. I just saw your response to my help here. Very sorry. I apologize. I just updated the script to look like...

Code: Select all

<?php 
$input = "og.jpg";
$output = "og-new.jpg";
$command = "./autocolor -m recolor –c separate $input $output";
error_log($command);
exec($command);
 ?>
But it seems to yield the same results.

Code: Select all

➜  tests  php auto.php
./autocolor -m recolor –c separate og.jpg og-new.jpg
convert: unable to open image `–c': No such file or directory @ error/blob.c/OpenBlob/2646.
convert: no decode delegate for this image format `–c' @ error/constitute.c/ReadImage/552.
convert: no images defined `./autocolor_1_5304.mpc' @ error/convert.c/ConvertImageCommand/3106.
I also retyped it all to be sure there were no hidden characters. Also my actual version of IM is 6.8.6-3 2013-07-06 Q16 if that helps.

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: AutoColor not working from PHP

Post by fmw42 »

did you try -c together?

The following fix inside the script seems to give me correct (non-grayscale) color results (using -c argument). viewtopic.php?f=3&t=24173#p103367

But this should have nothing to do with an error using -c.
./autocolor -m recolor –c separate og.jpg og-new.jpg
Is it possible that the minus in -c is not a normal hyphen, but either a short or long hyphen?
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

Re: AutoColor not working from PHP

Post by corbanb »

You nailed it on the hyphen. I did some more tests and now both together and separate are working! Great news!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: AutoColor not working from PHP

Post by fmw42 »

corbanb wrote:You nailed it on the hyphen. I did some more tests and now both together and separate are working! Great news!
Glad to hear that was all it was!
corbanb
Posts: 17
Joined: 2013-09-29T19:29:36-07:00
Authentication code: 6789

Re: AutoColor not working from PHP

Post by corbanb »

Thanks for all your help! Much appreciated. Doing testing now and plan to make some purchases in the near future.
Post Reply