Problem with Raw images, despite dcraw installed

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Problem with Raw images, despite dcraw installed

Post by lsmpascal »

Hi.
I'm very new to Imagick, even in Imagemagick. I simply try to convert CR2 or NEF files to jpg. I'm on it for 2 days without any solution.

I used this code :

Code: Select all

$im = new Imagick( 'source.CR2' );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'result.jpg' );
$im->clear();
$im->destroy();
The result is an error : Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/var/tmp/magick-80620Kc-ZP09ux4Rc.ppm': No such file or directory @ error/blob.c/OpenBlob/2658'

Note : if I try this code with a png or an hdr file everything is fine.

I asked the question on stackoverflow and people told me to install ufraw or dcraw. I installed both of them and the problem is still here.
I tested :
dcraw -i canonRaw_test.CR2
and it returns :
canonRaw_test.CR2 is a Canon EOS 60D image.
So dcraw is well installed.

I try the same code and the same cure on a Mac with MAMP and on a CentoS 6 server, with the same result.

Do I have to do something else after the ufraw or dcraw installation ?

Thanks
Last edited by lsmpascal on 2017-08-30T07:28:55-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with Raw images, despite dcraw installed

Post by snibgo »

This is PHP code, is it?

So your PHP code calls IMagick which calls ImageMagick which calls a delegate (ufraw or dcraw). It seems there is a problem at that stage, which ImageMagick is reporting, and that report goes back up the stack to you.

The ImageMagick file delegates.xml can tell you what delegate it is running, or trying to run. You can check from the command line whether the delegate works.

If that works, you might expand the delegates.xml entry to include the full pathname to the delegate.
snibgo's IM pages: im.snibgo.com
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

Thank you. I suspected something like that but I have no idear where this delegate file is. I don't know either what is the command line to see if the delegate works.
Can you enlight me, please ?
Thank you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with Raw images, despite dcraw installed

Post by snibgo »

What verson of IM?

This is on Unix? Sorry, I don't use Unix much. At a terminal window, type "where magick" or "whereis convert". (Maybe the command is "where". I forget.) This tells you IM's installation directory. In there, find the file "delegates.xml". This is a text file. In that file, find the line(s) with "dcraw" or "ufraw".

Then find the delegate program with "whereis" (or "where"). Change the lines in delegates.xml to include the full path to those files.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with Raw images, despite dcraw installed

Post by fmw42 »

On Unix, it is

Code: Select all

where -a magick

or

type -a magick
The -a reports all versions or installations that can be found in your PATH environment variable. If it is not in your PATH, then it might not be found.
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

As I can't install ufraw on my server (for the moment. I thought it was.) I want to give dcraw a try.

My delegates file is here : /etc/ImageMagick/delegates.xml
I opened it and found what I have to replace :

Code: Select all

<delegate decode="dng:decode" command="&quot;ufraw-batch&quot; --silent --create-id=also --out-type=png --out-depth=16 &quot;--output=%u.png&quot; &quot;%i&quot;"/>
by the code I found on the a site :

Code: Select all

<delegate decode="dng:decode" command="&quot;dcraw&quot; -c -q 3 -H 5 -w &quot;%i&quot; | &quot;/usr/bin/cjpeg&quot; -quality 100 > &quot;%o&quot;"/>
Pffffffff. It still fails. The same error, always.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with Raw images, despite dcraw installed

Post by snibgo »

What version of IM are you running?

Does IM convert at the command line? Does it work at all? Does it convert your CR2 file?
snibgo's IM pages: im.snibgo.com
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

Mt IM version : ImageMagick 6.7.2-7 2017-03-22 Q16

I installed ufraw on the server. Previously I had dependency problem.

So now with ufraw installed I can convert a .NEF !!! 2 days to achieve that... sometimes I'm not proud of me :)
But the problem is still here for the .CR2

The action :
[root@ns341732 ~]# /usr/bin/convert /home/lsmtest/www/usnap/canonRaw_test.CR2 /home/lsmtest/www/usnap/canonRaw_test.jpg

The server response :
My server speaks french so here is a translation :
convert: delegate failed `"ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"' @ error/delegate.c/InvokeDelegate/1057.
convert: impossible to open image `/tmp/magick-ijL8GjHK.ppm': Aucun fichier ou dossier de ce type @ error/blob.c/OpenBlob/2589.
convert: file name missing`/home/lsmtest/www/usnap/canonRaw_test.jpg' @ error/convert.c/ConvertImageCommand/3015.

That it.

By the way I didn't thank you. So I do it now : thank you for your time !
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

But I have another problem : if I can convert .nef file in command line, it still fails with imagick.

Code: Select all

$filename = 'nikonRaw_test.nef';
$im = new Imagick( $filename );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'nikonRaw_test_02.jpg' );
$im->clear();
$im->destroy();
returns :

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/tmp/magick-Coznuved.ppm': No such file or directory @ error/blob.c/OpenBlob/2589' in /home/lsmtest/www/usnap/index_trav.php:15 Stack trace: #0 /home/lsmtest/www/usnap/index_trav.php(15): Imagick->__construct('/home/lsmtest/w...') #1 {main} thrown in /home/lsmtest/www/usnap/index_trav.php on line 15
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with Raw images, despite dcraw installed

Post by snibgo »

lsmpascal wrote:So now with ufraw installed I can convert a .NEF !!!
How? Is this with just ufraw, or with "convert" that calls ufraw, or with IMagick?

Can you convert the CR2 with just ufraw?

You say that some things work and other things don't work. But you don't say exactly what works and what doesn't.
snibgo's IM pages: im.snibgo.com
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

Sorry, I will be clearer now.

1) The following command line works (it converts .nef to .jpg as wanted) :

Code: Select all

# /usr/bin/convert /home/lsmtest/www/usnap/nikonRaw_test.nef /home/lsmtest/www/usnap/nikonRaw_test.jpg
2) The following fails :

Code: Select all

# /usr/bin/convert /home/lsmtest/www/usnap/canonRaw_test.CR2 /home/lsmtest/www/usnap/canonRaw_test.jpg
with response :

Code: Select all

convert: delegate failed `"ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"' @ error/delegate.c/InvokeDelegate/1057.
convert: impossible to open image `/tmp/magick-ijL8GjHK.ppm': Aucun fichier ou dossier de ce type @ error/blob.c/OpenBlob/2589.
convert: file name missing`/home/lsmtest/www/usnap/canonRaw_test.jpg' @ error/convert.c/ConvertImageCommand/3015.
3) With imagick both are failing :

Code: Select all

$filename = 'nikonRaw_test.nef';
$im = new Imagick( $filename );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'nikonRaw_test_02.jpg' );
$im->clear();
$im->destroy();

// And :

$filename = 'canonRaw_test.CR2';
$im = new Imagick( $filename );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'canonRaw_test.jpg' );
$im->clear();
$im->destroy();

4) On your question "Can you convert the CR2 with just ufraw? " I didn't test it for the moment, because I don't really know how to do that.

Thank you.
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

I tried with ufraw-batch but I'm not sure to do it right. It fails :

Code: Select all

# ufraw-batch --out-type=jpeg /home/lsmtest/www/usnap/canonRaw_test.cr2
ufraw-batch: /home/lsmtest/www/usnap/canonRaw_test.cr2: unsupported file format.
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

Ok I tried with another .cr2 file and ufraw-batch managed to convert it in jpeg.
So let say my last problem is with imagick with allways the same response :

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/tmp/magick-Wo71j6cr.ppm': No such file or directory @ error/blob.c/OpenBlob/2589' in /home/lsmtest/www/usnap/index_trav.php:16 Stack trace: #0 /home/lsmtest/www/usnap/index_trav.php(16): Imagick->__construct('_MG_8639.CR2') #1 {main} thrown in /home/lsmtest/www/usnap/index_trav.php on line 16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with Raw images, despite dcraw installed

Post by snibgo »

From (1), we know that IM can call ufraw successfully, and ufraw can read your NEF, and return it to IM, and IM can process that. Good.

From (2), IM reports that ufraw failed, so ufraw didn't return an image to IM. It doesn't tell us why.

But you eventually discovered why:
lsmpascal wrote:unsupported file format
Ufraw can read the file, but cannot understand it. Perhaps it is corrupt.

For test (3) with IMagick, try editing your delegates.xml to use the full path to ufraw.
snibgo's IM pages: im.snibgo.com
lsmpascal
Posts: 9
Joined: 2017-08-30T06:47:57-07:00
Authentication code: 1151

Re: Problem with Raw images, despite dcraw installed

Post by lsmpascal »

And it works.
With the full path of ufraw-batch in the delegates.xml, it works !

You solved my problem.
I was desperate and now I can go on.
Thank you so much.
Post Reply