Paperclip on Windows - Photo is not recognized by the 'identify' command.

402 views
Skip to first unread message

neufelni

unread,
Jul 8, 2010, 9:01:01 AM7/8/10
to Paperclip Plugin
Hello,

I'm trying to install paperclip on Windows, and keep on getting the
following error when uploading an image:

Photo C:/Users/NICKNE~1/AppData/Local/Temp/stream,3492,0.gif is not
recognized by the 'identify' command.

I have tried every suggestion of I've found through Google search, and
have tried installing different versions of ImageMagick, including
installing it from source but keep getting the error.

I added some debug code in the run method of paperclip.rb to get some
more information about the issue. When I spit out the command that it
generates, I get this: C:/ImageMagick-6.6.3-Q16/identify '-format'
'%wx%h' 'C:/Users/NICKNE~1/AppData/Local/Temp/stream,3492,0.gif[0]'
2>NUL

When I run that, it just returns right away without any output, no
errors or anything. The run method raises the following exception:
Error while running identify. Expected return code to be 0 but was 1

If I try to just run C:/ImageMagick-6.6.3-Q16/identify C:/Users/
NICKNE~1/AppData/Local/Temp/stream,3492,0.gif, it correctly returns
the dimensions.

Any idea what's going on here?

Thanks,
Nick

mikej

unread,
Jul 8, 2010, 9:58:55 AM7/8/10
to papercli...@googlegroups.com
Nick,

You said it works for the following:

If I try to just run C:/ImageMagick-6.6.3-Q16/
identify C:/Users/NICKNE~1/AppData/Local/Temp/stream,3492,0.gif, it correctly returns
the dimensions.

Did you try running the following which is what you state the debug says it runs:
C:/ImageMagick-6.6.3-Q16/
identify '-format' '%wx%h' 'C:/Users/NICKNE~1/AppData/Local/Temp/stream,3492,0.gif[0]' 2>NUL

It looks like the single quotes are likely causing the problem. Take a look at the recent posts as I believe others have described the same issue and solutions in the later versions of Paperclip with one of the later Rails versions.

Mike



--
Individuals over processes. Interactions over tools.

Agile Rails training from thoughtbot, the makers of Paperclip, Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training

The Paperclip group:
http://groups.google.com/group/paperclip-plugin

To post to this group, send email to
papercli...@googlegroups.com

To unsubscribe from this group, send email to
paperclip-plug...@googlegroups.com

neufelni

unread,
Jul 8, 2010, 11:50:33 AM7/8/10
to Paperclip Plugin
Thank you Mike, It turns out it was the single quotes. In the lib/
paperclip.rb file, I just needed to replace the "'#{m}'" with "\"#{m}
\"" in the quote_command_options method.

def quote_command_options(*options)
options.map do |option|
option.split("'").map{|m| "\"#{m}\"" }.join("\\'")
end
end

Is there any chance this change could cause any other issues?

Thanks,
Nick
> > paperclip-plug...@googlegroups.com<paperclip-plugin%2Bunsubscrib e...@googlegroups.com>

mikej

unread,
Jul 8, 2010, 12:05:06 PM7/8/10
to papercli...@googlegroups.com
Nick,

I actually don't have experience with the issue. Hopefully others can provide more feedback. I happened to see your post and had read some other posts recently that mentioned a similar issue.

Mike

Jonathan Yurek

unread,
Jul 8, 2010, 4:16:39 PM7/8/10
to papercli...@googlegroups.com
So as it turns out, Windows (or, specifically, cmd.exe) doesn't have the same shell escaping issue that bash, etc. do. So I can probably remove the quoting entirely if I detect I'm on Windows. However, that does nothing to help you right this moment. :)

The good news is that you can probably just remove the #map and #split (but keep the #join) entirely and it will work fine for now.

--
Jonathan Yurek, Founder and CTO
thoughtbot, inc.
organic brains. digital solutions.

617.482.1300 x114
http://www.thoughtbot.com/

Keone

unread,
Jul 16, 2010, 9:46:27 AM7/16/10
to Paperclip Plugin
neufelni's fix, applied to line 66 (in shell_quote) of command_line.rb
fixes the identify issue for me.

additionally, I needed to make a change to thumbnail.rb because the
options on resize and crop have single quotes and ImageMagick does not
like this. Here are my amended lines (74-75):

trans << "-resize" << "\"#{scale}\"" unless scale.nil? ||
scale.empty?
trans << "-crop" << "\"#{crop}\"" << "+repage" if crop

This fails:

C:\Users\Keone\Desktop\tmp>convert "C:/Users/Keone/AppData/Local/Temp/
stream,6576,0.jpg[0] -resize '300x' -crop '300x300+0+0' +repage "C:/
Users/Keone/AppData/Local/Temp/stream,6576,0,6576,0.jpg

This works:

C:\Users\Keone\Desktop\tmp>convert "C:/Users/Keone/AppData/Local/Temp/
stream,6576,0.jpg[0]" -resize "300x" -crop "300x300+0+0" +repage "C:/
Users/Keone/AppData/Local/Temp/stream,6576,0,6576,0.jpg

Thanks for the plugin, Jonathan.
Message has been deleted

Jon Yurek

unread,
Sep 7, 2010, 9:40:07 AM9/7/10
to papercli...@googlegroups.com
Hi,

Paperclip is currently passing all tests on Windows (assuming you have file.exe installed), so this should definitely be working. Can you paste your configuration so we can see if there's anything wrong? Please include both your model and any initializers.

On Sep 4, 2010, at 9:34 PM, ed wrote:

> Hi,
>
> Really need your help to fix the 'identify command not found error'. I
> have spent 2 full days on this trying to resolve this issue.
>
> I have paperclip running on rails 3.0.0.RC and Windows XP. It work
> fine, however if I uses the styles options in the has_attached_file
> method I got the error below:
>
> Document C:/DOCUME~1/Ed/LOCALS~1/Temp/stream,10144,2.doc is not


> recognized by the 'identify' command.

> http://gist.github.com/565653 (Full details of error)
>
> I can run 'identify' from the command line as well without a problem.
> I have command_path with no success.
> I've re-installed and tried 3 different versions of ImageMagick as
> well.
>
> I followed neufelni's fix to no avail and couldn't follow yous as i
> couldn't locate the files you mentioned like command_line.rb.
>
> Thanks for your help.
>
> Cheers

617.482.1300 x114
http://thoughtbot.com/
http://twitter.com/thoughtbot

Agoofin

unread,
Sep 7, 2010, 6:13:00 PM9/7/10
to Paperclip Plugin
Ed,

You can get to the local files by issuing the command: 'bundle show
paperclip' in a shell. It will be in your local gem directory. If
you're using paperclip 2.3.3 then look at paperclip.rb line 133.
Inside the map block, there is a double quoted string with single
quotes around #{m}, just remove the single quotes.



On Sep 4, 9:34 pm, ed <bauchir...@gmail.com> wrote:
> Hi,
>
> Really need your help to fix the 'identify command not found error'. I
> have spent 2 full days on this trying to resolve this issue.
>
> I have paperclip running on rails 3.0.0.RC and Windows XP. It work
> fine,  however if I uses the styles options in the has_attached_file
> method I got the error below:
>
> Document C:/DOCUME~1/Ed/LOCALS~1/Temp/stream,10144,2.doc is not
> recognized by the 'identify' command.http://gist.github.com/565653 (Full details of error)
>
> I can run 'identify' from the command line as well without a problem.
> I have command_path with no success.
> I've re-installed and tried 3 different versions of ImageMagick as
> well.
>
> I followed neufelni's fix to no avail and couldn't follow yous as i
> couldn't locate the files you mentioned like command_line.rb.
>
> Thanks for your help.
>
> Cheers
>
> On Jul 16, 2:46 pm, Keone <keone....@gmail.com> wrote:
>
>
>
>
>
>
>

Agoofin

unread,
Sep 7, 2010, 6:26:26 PM9/7/10
to Paperclip Plugin
Jon,

I had the same problem but wasn't doing anything special. In my test
project I made sure the ImageMagic directory was part of the path and
did not set any options in development.rb:

class Item < ActiveRecord::Base
# Paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100",
:small => "150x150" }

end

With the straight 2.3.3 gem, I received the same errors that Ed posted
to gist. After changing the paperclip.rb as mentioned above it worked
just fine.

Also, what do you mean about file.exe?

jazzhermit

unread,
Sep 19, 2010, 6:12:46 PM9/19/10
to Paperclip Plugin
I too would be interesed in what Jon meant by file.exe.

Dennis

unread,
Sep 20, 2010, 11:30:03 AM9/20/10
to Paperclip Plugin
This link might give some insights into file.exe: (Ihaven't tried it
yet myself...

http://www.vowles-home.demon.co.uk/utils/windows_file_exe.htm

I suggest you read down the article a bit as there is more than one
version of this exe out there. As for myself, I had problems with
identify.exe under windows but was able to fix the problem by making
this change:

# command = %Q[#{path_for_command(cmd)} #{params}]
command = %Q[#{path_for_command(cmd)} #{params.gsub("'",'"')}]

to the paperclip.rb library file (around line 110 for the file I have)

I really don't like kludge fixes, so I'll be downloading the file.exe
to give it a try and see if it allows me to remove the change to the
paperclip.rb file.

I found the temporary fix here:

http://railscasts.com/episodes/134-paperclip

under comment 138 (vuitton neverfull )

which I was quite thankful for at the time as it got paperclip up and
running for me under my windows development machine.

Jon Yurek

unread,
Sep 20, 2010, 8:36:23 PM9/20/10
to papercli...@googlegroups.com
By file.exe, I meant the "file" utility, but for windows: http://gnuwin32.sourceforge.net/packages/file.htm

Reply all
Reply to author
Forward
0 new messages