1

I'm trying to use imagemagick-7 (CLI) on ubuntu to identify and convert RAW images to PNG format. I am using the dcraw binary as the delegate for identifying and converting raw images.

I updated the dng:decode delegate in delegates.xml as follows:

<delegate decode="dng:decode" command="&quot;dcraw&quot; &quot;%i&quot;" />

When I run this command: magick identify test.dng, I get the following error:

identify: unable to open image '/tmp/magick-24332a6nW8lcwejNJ.ppm': No such file or directory @ error/blob.c/OpenBlob/3489.

The same error is given for magick convert. I noticed that imagemagick is generating a temporary intermediate file in my /tmp directory, which has a different name than the name it's expecting to find there. For example, it generates this file - magick-24332P6aVDePOFeCn.ppm - but is expecting the file it generated to have this name - magick-24332a6nW8lcwejNJ.ppm - which is why it's not finding it.

Note: I tested the same thing on OS X and it works perfectly fine (with the same delegates.xml configuration).

Is this a bug in imagemagick's implementation for unix systems or am I doing something wrong? Any thoughts would be greatly appreciated!

corecase
  • 1,278
  • 5
  • 18
  • 29
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Sep 13 '18 at 22:53
  • 1
    This is not a Unix question; it's a question about a *command-line application* that is available on Windows, OS X and Unix. Since it's about an application, which as a side note I am also using in a development project, I believe that this is the right place to ask this question. It is much less likely for someone on the exchanges you linked to have an answer to this question, than someone on SO. – corecase Sep 13 '18 at 23:01
  • You are probably missing some arguments for dcraw in your delegates.xml file. But ImageMagick 7 nominally uses ufraw-batch in place of dcraw. It may not work right with dcraw. Try installing ufraw and go back to your original delegate.xml file. – fmw42 Sep 13 '18 at 23:24
  • Are you sure you installed dcraw properly so that ImageMagick can find it on your Linux system? What is your ImageMagick version and date of that version on your Linux system. The date is more important than the version, since Linux updates are just patches the do not always changing the version. The patch may be old or buggy as not fixes are always included. Sometimes only security issue are patched. You can see what version and date from `convert -version`. – fmw42 Sep 13 '18 at 23:51
  • Thanks for the response @fmw42 -- version and date are `Version: ImageMagick 7.0.8-11 Q16 x86_64 2018-09-13`. I'm trying to use dcraw instead of ufraw-batch, because ufraw-batch is not being able to handle most of the raw image files/extensions that I have... I am pretty sure I installed ImageMagick and dcraw properly on my system; I built ImageMagick from source, using the directions they provide in their docs, and I installed dcraw using apt. dcraw works properly when I use it on its own. – corecase Sep 14 '18 at 00:15
  • The version and date you installed is fine. Do you see "raw" or "dcraw" included in the delegates. If not, perhaps ImageMagick cannot find dcraw. I am not that familiar with dcraw. But I have ufraw and it shows in my magick -version as "raw". But since you can get it to work on your Mac, but not your Linux, I have to assume your Linux imagemagick is not finding it properly or it did not install correctly. My guess is the former, since you say you can run it directly without ImageMagick – fmw42 Sep 14 '18 at 02:38
  • I found this comment on the ImageMagick forum. `The only patch that IM adds to dcraw is for the "-O" option.` That was in regard to Windows question, but may apply to any OS. Did you add that to your delegates.xml file for dcraw. – fmw42 Sep 14 '18 at 02:45
  • Just tested it, I get this error: `identify: delegate failed 'dcraw' '%i' -O '%o'' @ error/delegate.c/InvokeDelegate/1844` :( – corecase Sep 14 '18 at 02:54

3 Answers3

2

You were close the right command to use in delegate is

<delegate decode="dng:decode" command="&quot;dcraw&quot; -c &quot;%i&quot; &gt; &quot;%u.ppm&quot;" />
1

Almost! You need to use the %o placeholder to tell the delegate manager were the output file will be written to. However the dcraw utility doesn't have in output destination options -- at least from what I can tell form the man-page. It does have a stdout option (-c), so you should be able to pipe/redirect the stream to an output location.

dcraw -c %i > %o

or in delegate XML.

<delegate decode="dng:decode" command="&quot;dcraw&quot; -c &quot;%i&quot; &gt; &quot;%o&quot;" />

Update

Some tricks I've observed with custom delegations.

  • Use full path to binaries. Usually because I installed something outside of the systems PATH. Usually /usr/local/bin or /opt directories.

    command="/usr/local/bin/dcraw ...
    
  • Use mv over pipes. If your not comfortable with debugging unix streams & such. Just do some basic copy/move command. We can rewrite the above command with something like...

    dcraw %i; mv %i.ppm %o
    
  • Ignore escaping quotes until you know its working. Encapsulating arguments are important, and keep everything safe, but \"%i & &quot;%i are hard to read.

    <delegate decode="dng:decode" command="dcraw %i; mv %i.ppm %o" />
    

    ... verify things are called correctly ... then probably escape paths.

    <delegate decode="dng:decode" command="dcraw &quot;%i&quot;; mv &quot;%i&quot;.ppm &quot;%o&quot;" />
    
  • As pointed out previously, use identify -list Delegate to verify that the command is loaded correctly, and -verbose to verify that it was called correctly during runtime.

emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Thanks for the suggestion! I'm getting this error now: `Cannot decode file /tmp/magick-24352rjx4_TOof7EE identify: delegate failed 'dcraw' -c '%i' > '%o'' @ error/delegate.c/InvokeDelegate/1844`. I double checked the quotes to make sure they all line up properly, so that doesn't seem to be the issue... Any idea? – corecase Sep 14 '18 at 02:07
  • Probably a typo I posted. Run a simple convert with a `-verbose` flag to see if the correct command is issued. Also run `identify -list Delegate` to dump all custom delegates and check if it's loaded without any conflicts with other `dng` decoders. – emcconville Sep 14 '18 at 12:50
  • Thanks for the updates, very helpful -- I'm trying this now ``, but I'm getting a `permission denied` (looks like it's for the `touch`). I'm trying to do a touch, because the pipe expects the file to exist; you need to pipe dcraw's `-c` output to an existing file, as it simply pipes it to stdout otherwise. Trying to figure out how I can get around the permission denied - I am running `magick convert` as root, so I'm not sure why it wouldn't allow the command to go through... – corecase Sep 14 '18 at 17:18
  • Try this... `dcraw %i; mv %i.ppm %o`. There error your getting is because %i.ppm is not an executable. – emcconville Sep 14 '18 at 18:17
  • That didn't work, but I got this command to get rid of that error: ``. However, now I'm getting an error saying `identify: unable to open image '/tmp/magick-24846lwise06TPve7.ppm'`; and the weird thing is that this filename is neither the %i nor the %o filename... I'm baffled! – corecase Sep 14 '18 at 18:28
  • Replace `dcraw -c %i | %i.ppm;` with `dcraw -c %i > %i.ppm;` . If that doesn't work, we may need to move to chat to debug. – emcconville Sep 14 '18 at 18:41
0

For anyone else who experiences this problem, my solution ended up being to switch from imagemagick to graphicsmagick, which is by default configured to use dcraw (of course, you need to have dcraw installed and on your PATH).

http://www.graphicsmagick.org/

corecase
  • 1,278
  • 5
  • 18
  • 29