imagemagick - php magick (not imagick library) using ufraw-batch conversion from raw to jpeg not working

I am trying to convert a variety of raw images into jpeg files using php, an exec call directly to magick and have the delegate ufraw convert the image.
I'm doing it this way because the imagick library didn't give me the results I wanted.
This is my script:
exec('/usr/local/bin/magick /path/to/image/CRW_7864.CRW -compress jpeg -quality 50 /path/to/image/CRW_7864.jpeg 2>&1', $output);
var_dump($output);
The dump is so that I can see all the outputs. The call in the delegates.xml file for imagemagick doesn't have --silence so that I can see all the output for it. The delegate line looks like this:
<delegate decode="dng:decode" command="/usr/local/bin/ufraw-batch --out-type=jpeg "--output=%u" "%i""/>
The conversion fails:
array(3) { [0]=> string(53) "ufraw-batch: Loaded /var/tmp/magick-36451MMV_GgkGDl9p" [1]=> string(193) "ufraw-batch: overwrite '/var/tmp/magick-36451iMjYJmSd4yhV'? [y/N] magick: delegate failed `/usr/local/bin/ufraw-batch --out-type=jpeg '--output=%u' '%i'' @ error/delegate.c/InvokeDelegate/1897." [2]=> string(125) "magick: unable to open image '/var/tmp/magick-36451iMjYJmSd4yhV.ppm': No such file or directory @ error/blob.c/OpenBlob/3496." }
Now here's the weird thing, the code for ufraw (in delegates.xml) works when I input it directly into terminal.
I have set the permissions so that the user (set in my .htdoc) has access to all relevant image files
From what I can tell, ufraw takes the image sent by magick to it and accepts it. Then it tries to move it to somewhere and overwrite another temp file? Then falls down.
I have spent 3-4 days on this now and I am stumped. Any help or clarity would be greatly appreciated.
Running:
Apache 2.4.43
php 7.4.6_1
imagemagick 7.0.10-18
Answer
Solution:
I had an epiphany late last night.
when ufraw saves the temp file it takes from Magick, it uses the name it gets from Magick. However, Magick then looks for a file with the filetype '.ppm'
Therefore I have to force the overwrite, and change the delegate command so that ufraw saves the temp file with the '.ppm' at the end
<delegate decode="dng:decode" command="/usr/local/bin/ufraw-batch --out-type=jpeg --overwrite "--output=%u.ppm" "%i""/>
This worked. I can now run the original exec command and convert the '.CRW' to '.JPEG'.
Some things to point out that I learned from all this:
ImageMagick delegates command code needs to be tested in command line before you rely on it. If the delegate falls over, you won't know why, it will just fail.
Feedback is essential. in the exec call, have the stdout and stderr output so you can see what is going on. Add2>&1
to the end of the call. (See original exec call)
Add--verbose
to the exec call to see more information about what is going on.
Remove `--silence' from the ufraw delegate command (in imagemagick) when testing it in command line. This gives you more feedback.
Be mindful of your permissions (who owns what and who can do what to which), file types (what different programs are looking for) and naming.
Use full paths to programs within programs.
UPDATE
I continued to work on this for other RAW types (ARW, NEF, etc) and I found that ufraw was struggling to identfy some of these (temp files don't have the extensions). It was treating them as .tiff files and not being able to handle the conversion.
The answer to this was given to me by a user on here.
Uploading of camera RAW files to a web server. File type issue. Is there a work around?
Basically, when you call imageMagick on a temp file you should prefix the file type to the call. This will tell ImageMagick what delegate to use for it.
exec('/usr/local/bin/magick ARW:/path/to/image/tempfile -verbose -compress jpeg -quality 50 /path/to/image/filename.jpeg 2>&1', $output);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: please make sure the php redis extension is installed and enabled.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.