Page 1 of 1

convert: Error when saving the profile into a file

Posted: 2014-04-14T11:17:50-07:00
by epaaj
Hi,

I have a problem when running a convert command through a php-script via Apache server on Arch Linux. It seems to be working fine when I run it in shell as myself. And there have been cases where I get this error and the output file is still created.
The php-script is run as user http which has write access to both folders involved.

One example of what I'm trying to run:

Code: Select all

convert -alpha Set -filter bessel -resize '200'x'200' -density '200'x'200' 'image.eps' -channel A -fx 'B' -negate '/var/im/4.png'
This returns:

Code: Select all

convert: Error when saving the profile into a file '.' @ warning/opencl.c/autoSelectDevice/2303.
What does this error mean? What profile is it trying to save and to where?
I only seem to find old posts where it has been posted that it will be solved in a later version.

Code: Select all

convert --version
Version: ImageMagick 6.8.9-0 Q16 x86_64 2014-04-13 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL OpenMP
Delegates: bzlib cairo fontconfig freetype gslib jng jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib
Thanks for any help in advance!

Re: convert: Error when saving the profile into a file

Posted: 2014-04-14T11:23:16-07:00
by Bonzo
Your command order could be the problem as you read the image in first - apart from a couple of options.

I would try:

Code: Select all

convert -density 200x200 'image.eps' -alpha Set -filter bessel -resize 200x200 -channel A -fx B -negate '/var/im/4.png'
If it still does not work a link to a image will probably help other trace your problem.

I would also start simple and build up you command so you can fault find each part as its added not try and fault find the whole lot in one go.

Re: convert: Error when saving the profile into a file

Posted: 2014-04-14T11:54:02-07:00
by fmw42
-channel A -fx 'B'
You seem to be limiting processing to the alpha channel and then having -fx select the blue channel. This is a very odd statement in my opinion. Perhaps I misunderstand.
convert -alpha Set -filter bessel -resize '200'x'200' -density '200'x'200' 'image.eps' -channel A -fx 'B' -negate '/var/im/4.png'
What is the goal of your command in simple language?

You seem to adding an opaque alpha channel by -alpha set, then after resizing, you seem to select the alpha channel and then negate. If that is the case, then all you will get is an perfectly transparent image, since the alpha channel will go from white to black.

Perhap you just want to negate the blue channel. Then

Code: Select all

convert -density "200x200 "image.eps" -alpha Set -filter bessel -resize "200x200" -channel blue  -negate +channel "/var/im/4.png"
or

Code: Select all

convert -density "200x200 "image.eps" -alpha Set -filter bessel -resize "200x200" -channel blue  -negate -channel rgba "/var/im/4.png"

I am not sure it is wise to put images into /var

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T04:15:04-07:00
by epaaj
Thanks for the advises but the problem does not seem to be with the commands themselves, but with running them via Apache/php. After testing this further I would assume that the problem is that the environment for the user running with Apache is too limited and is missing something that is needed for this to work. I don't know what this profile is or where it should be saved but it seems that either there is something wrong with some variable for the apache user's home folder or some other restriction.

I probably need a way to prevent the profile from having to be saved or to remove limitations for how Apache handle running external commands for the user it is ran as.

Any suggestions for any of those two solutions?

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T04:31:20-07:00
by snibgo
Something else to check: is PHP running the same version of IM as the command line?

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T04:41:32-07:00
by epaaj
The version seems to be the same but it does not use the same path to the executable.

From shell:

Code: Select all

/usr/bin/convert
Version: ImageMagick 6.8.9-0 Q16 x86_64 2014-04-13 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL OpenMP
Delegates: bzlib cairo fontconfig freetype gslib jng jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zli
From within PHP:

Code: Select all

/usr/sbin/convert
Version: ImageMagick 6.8.9-0 Q16 x86_64 2014-04-13 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL OpenMP
Delegates: bzlib cairo fontconfig freetype gslib jng jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib
Also:
It works fine if I run the same script from shell by running "php -f testfile.php". Therefore I believe the problem is with Apache rather than PHP or ImageMagick. But with this I run it as myself in full environment, which Apache probably does not do for its user.

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T04:41:49-07:00
by Bonzo
I have run Imagemagick without a problem with php on multiple servers with default settings. Both by uploading through a form and by dropping into the folder via FTP.
Most of the servers have been Centos and so I assume it must be a problem with your setup or Arch Linux is to simple?

I would try a simple command first - just convert a png to jpg or something to see if the basic Imagemagick operations work with php.
But I would guess you need to talk to somebody else who uses Arch Linux or post on their forum.

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T04:43:12-07:00
by Bonzo
You can specify the path to convert:

exec( "/usr/bin/convert input.png output.jpg");

Re: convert: Error when saving the profile into a file

Posted: 2014-04-16T05:38:16-07:00
by epaaj
That sample you suggested worked fine, without any errors. I also did some additional testing. The two seperate commands below still generates the same error each time but the output seems to be correct.
What it should do is take all the blue and remove it, making it transparant. And by seperating the commands it now works. But what does the error mean as I still get it.

Code: Select all

shell_exec("/usr/bin/convert 'image.eps' -alpha Set -filter bessel -channel A -fx 'B' -negate '/var/im/4.png' 2>&1");
shell_exec("/usr/bin/convert '/var/im/4.png' -density '200'x'200' -resize '200'x'200' '/var/im/5.png' 2>&1");