thoughtbot / paperclip

Easy file attachment management for ActiveRecord
https://thoughtbot.com
Other
9.01k stars 2.43k forks source link

NotIdentifiedByImageMagickError for *.jpg #2055

Closed abrambailey closed 8 years ago

abrambailey commented 8 years ago

I am receiving this error occasionally from my server, which is running Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-40-virtual x86_64):

  Paperclip::Errors::NotIdentifiedByImageMagickError
  app/models/user.rb:142:in `avatar_geometry'

Here is line user.rb:142 @geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))

Parameters of the request:

  * Parameters : {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"+P9HZqeLr30Mf9k4Q27oSpG9rVE9JKb9m3LYNS13WJ0OJcfxMgzmOWMaEeNjhHqJMFRIBc2Ihyec4tRIw6uY/g==", "user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fb306f7a1a0 @tempfile=#<Tempfile:/tmp/RackMultipart20151116-31114-hqi89z.jpg>, @original_filename="P1-a96bd.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"P1-a96bd.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Crop Uploaded Image", "controller"=>"users", "action"=>"crop"}

Output of $ convert -list configure

app@mothership:~/site.com/current$ convert -list configure

Path: /usr/share/ImageMagick-6.6.9/configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            gcc -std=gnu99 -std=gnu99
CFLAGS        -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/lqr-1 -fopenmp -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Wall -pthread
CODER_PATH    /usr/lib/ImageMagick-6.6.9/modules-Q16/coders
CONFIGURE     ./configure  '--prefix=/usr' '--sysconfdir=/etc' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--with-modules' '--with-gs-font-dir=/usr/share/fonts/type1/gsfonts' '--with-magick-plus-plus' '--with-djvu' '--enable-shared' '--without-dps' '--without-fpx' '--with-perl-options=INSTALLDIRS=vendor' '--x-includes=/usr/include/X11' '--x-libraries=/usr/lib/X11' 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro' 'CPPFLAGS=-D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security'
CONFIGURE_PATH /etc/ImageMagick/
COPYRIGHT     Copyright (C) 1999-2011 ImageMagick Studio LLC
CPPFLAGS      -I/usr/include/ImageMagick
CXX           g++
CXXFLAGS      -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -pthread
DEFS          -DHAVE_CONFIG_H
DELEGATES     bzlib djvu fontconfig freetype gvc jpeg jng jp2 lcms lqr openexr png rsvg tiff x11 xml wmf zlib
DISTCHECK_CONFIG_FLAGS 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security' 'CPPFLAGS=-D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro' --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-dps=no --with-fpx=no --with-gslib=no --with-fontpath= --with-gs-font-dir=/usr/share/fonts/type1/gsfonts --with-perl=no
DOCUMENTATION_PATH /usr/share/doc/ImageMagick-6.6.9/
EXEC-PREFIX   /usr
EXECUTABLE_PATH /usr/bin
FEATURES      OpenMP 
FILTER_PATH   /usr/lib/ImageMagick-6.6.9/modules-Q16/filters
HOST          x86_64-unknown-linux-gnu
LDFLAGS       -L/usr/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/X11
LIB_VERSION   0x669
LIB_VERSION_NUMBER 6,6,9,7
LIBRARY_PATH  /usr/lib/ImageMagick-6.6.9
LIBS          -lMagickCore -llcms -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lm -lgomp -lpthread -lltdl
NAME          ImageMagick
PCFLAGS       -fopenmp
PREFIX        /usr
QuantumDepth  16
RELEASE_DATE  2014-03-06
SHARE_PATH    /usr/share/ImageMagick-6.6.9
SVN_REVISION  4345
TARGET_CPU    x86_64
TARGET_OS     linux-gnu
TARGET_VENDOR unknown
VERSION       6.6.9
WEBSITE       http://www.imagemagick.org

I cannot seem to replicate this error with other jpg images, so I'm having a real hard time isolating the issue. This is from user.rb:

    has_attached_file :avatar, :styles  => { :small => "100x100#", :thumbnail=> "200x200", :medium =>"300x300", :large => "500x500>" }, :default_url => "avatar_unknown.jpg", :processors => [:cropper]

Finally, cropper.rb:

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ') # super returns an array like this: ["-resize", "100x", "-crop", "100x100+0+0", "+repage"]
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end
    end
  end
end

Using ImageMagick 6.6.9-7 and paperclip 4.1.1

abrambailey commented 8 years ago

Just a quick update that delegates for *.jpg do not appear to be the issue:

app@mothership:~$ identify /tmp/RackMultipart20151116-31114-hqi89z.jpg
/tmp/RackMultipart20151116-31114-hqi89z.jpg JPEG 2400x3000 2400x3000+0+0 8-bit DirectClass 4.235MB 0.000u 0:00.039
tute commented 8 years ago

@abrambailey could you figure out your issue?

tute commented 8 years ago

Closing due to lack of activity. If this is still an issue for you, let me know and we continue triaging this. Thanks!

abrambailey commented 8 years ago

@tute Sorry about that, I guess I solved this, and can't even remember how now.