0

I am migrating my application online with Heroku and Amazon AWS (S3) and encountered a weird error for my profilepic model.

This model manages the profile pic. It is made of 2 Paperclip attachments and a few other fields and depends to another model called Professionnel.

Here is the model :

class Profilepic < ApplicationRecord

  belongs_to :professionnel

  has_attached_file :image, styles: { original: "6000x6000", editable: "1200x1200", thumbnail: "400x400#"}
  validates_attachment :image, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }, size: {less_than: 10.megabytes}

  has_attached_file :finalimage, styles: { medium: "500x500", small: "200x200"}, processors: [:cropper]

  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h

end

First attachment :image is the image uploaded by the user. The second image (:finalimage) is a cropped image after Professionnel user has edited it (with cropper.js)

Everything is working perfectly locally

Though, when the image is uploaded the following bit of code is returning Paperclip::Errors::NotIdentifiedByImageMagickError

The bit of code that triggers this error is :

nouvelleppic.ratiolongdivlarg = Paperclip::Geometry.from_file(nouvelleppic.image.path(:original)).width / Paperclip::Geometry.from_file(nouvelleppic.image.path(:original)).height

In this bit of code, I am discovering the width/height ratio with help from Paperclip geometry functions.

Not sure what's wrong. It does work locally flawlessly and I am querying this AFTER the :image is successfully saved into my S3 bucket (I checked in S3 console)

I need this ratio to create the view that will allow user to crop the image and turn it into :finalimage. This is really funny it doesn't work when migrationg to Heroku / S3 as it is a simple geometry function from Paperclip. No problem uploading ...

EDIT EDIT

seems the problem is identified :

https://github.com/thoughtbot/paperclip/issues/2198

I just checked the Imagemagick version on my Heroku Cedar14 stack: 6.7.7-10 !!

Version: ImageMagick 6.7.7-10 2016-11-29 Q16 http://www.imagemagick.org

as suggested in the git thread above, is there a way to upgrade ImageMagick at Heroku ??

This thread How can I use the latest version of Imagemagick on Heroku? seems to suggest we can do that (second answer) ??

Community
  • 1
  • 1
Maxence
  • 2,029
  • 4
  • 18
  • 37

1 Answers1

0

In response to your second question. The way you update Image Magic on heroku is by using a buildpack. Just like you have right now a Ruby buildpack you will have to add an Image Magic buildpack. Heroku has a dedicated page for Image Magic buildpacks:

https://elements.heroku.com/search/buildpacks?utf8=%E2%9C%93&q=imagemagick

This one (below) seems to be the most popular but feel free to browse around: https://elements.heroku.com/buildpacks/mcollina/heroku-buildpack-imagemagick

Alexander Luna
  • 5,261
  • 4
  • 30
  • 36
  • thank you for this. This is great to know I can change ImageMagick version. Though I am not even sure it would fix my issue. Will try the fix mentionned in the git Thread. It is much more advanced Ruby than I can do but I will give it a try .. – Maxence Apr 16 '17 at 20:11
  • One stupid thing: I am checking dimensions of an image stored remotely. Is it not possible to check this eventhough the model has not yet been saved and then the image not yet processed by paperclip ? Like the temp file ? – Maxence Apr 16 '17 at 20:49
  • damn got it !! http://stackoverflow.com/questions/4065295/saving-the-images-dimensions-width-and-height-in-paperclip – Maxence Apr 16 '17 at 20:53