Rails Active Storage image variant flipped upside down - ruby-on-rails

When rendering a rails active storage image variant as follows:
<%=image_tag(current_user.avatar.variant(resize_to_limit:[200, 200])) %>
The image gets flipped upside down. I have tried to remove the EXIF metadata by setting the auto_orient option as true like suggested here without success. This is definitely a rails bug because as soon as I remove the variant method, the original image displays correctly.
Note that I am uploading picture captured by iphone devices. Here is the image used.
System configuration:
Rails version: 6.1.5 /
Ruby version: 3.1.1p18

I've finally solved the problem by updating the backend the image_processing gem was using under the hood on my local machine (Apple Silicon, M1 chip). So, it was not really a rails issue, but something you should keep in mind when using Active storage variants.

Related

Rails preview for active storage videos not working

I have a pretty standard model where you can upload videos - so far so good.
The video gets uploaded and is also displayed on the show view. Alle seems to be fine....but:
I cannot get a preview fo to work.
ActiveStorage::Blob.last.previewable?
--> false
ActiveStorage::Blob.video?
--> true
FFMPEG is installed on the system and in the gem file
which ffmpeg
--> /usr/local/bin/ffmpeg
gem 'streamio-ffmpeg'
And of course if I run preview directly, I get an error
ActiveStorage::Blob.last.preview(resize: "200x200>").processed
--> ActiveStorage::UnpreviewableError (ActiveStorage::UnpreviewableError)
Previewers is having video included
Rails.application.config.active_storage.previewers
--> [ActiveStorage::Previewer::PopplerPDFPreviewer, ActiveStorage::Previewer::MuPDFPreviewer, ActiveStorage::Previewer::VideoPreviewer]
I also tried different video formats, but nothing works and I am out of ideas where to look.
Anybody had the same issue?
I had face the same issue, please follow the below step which might help you because it work for me.
install the ffmpeg
install the ImageMagick
attribute :video_preview do |object|
Rails.application.routes.url_helpers.rails_representation_url(object.video.preview(resize: "200x200").processed, only_path: true)
end
use this method to check whether is working or not.
I had a similar problem of video previews working fine locally but not playing in production. It was simply because I hadn't installed ffmpeg in my production environment.
My production environment was heroku, so I simply added the ffmpeg buildpack like so:
heroku buildpacks:add --index 1 https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
And then everything worked as expected.

discrepancy between development and production pdf generated

I've Iterated over the creation of a PDF with data in my RoR application. I am using wkhtmltopdf 0.9.9 locally and trying to use wkhtmltopdf-binary (0.9.9.1) gem on heroku.
My PDF looks exactly the way I want it to look locally but it looks like the heroku version is a zoomed out version of the local version effectively making the page on heroku left align when the development version is perfectly centered.
I'd like my production version to look exactly like my development version so that I don't have to iterate on my heroku instance.
Any help is appreciated!
I had the same problem, but setting DPI, while generating pdf via wkhtmltopdf, solved the problem.
--dpi 100

Image uploads with Rails/CarrierWave: How does ImageMagick work once app is deployed?

I'm trying to enable image uploads for a model in my Rails app. I'm using the CarrierWave gem, but in order to do any image manipulation like thumbnail resizing I must have Imagemagick installed on the actual computer for use with the Rmagick gem.
Here's the problem: I'm turning this app over to a painter who will log in and upload her own art. This means she won't be in my development environment that has Imagemagick installed. I'm really confused about the role of Imagemagick here - will image manipulation simply not work anymore when the app is deployed, or does it persist somehow?
Feel free to correct me if my understanding of this is completely screwy. Or, is there a better solution available?
ImageMagick must be installed to install RMagick; RMagick is an interface to ImageMagick's libraries, and calls ImageMagick's functions to do its processing.
If the ImageMagick libraries and development headers are not present on the deployed machine, RMagick installation will fail.
When you 'turn over' your app to the painter what this really means is that you'll deploy your application to a platform like Heroku (i.e. a production environment) that will host your Rails app for you. If you choose Heroku, all will be well because their Rails setup includes Imagemagick and you don't need to do anything.
The key here is to ensure that whatever provider you use to host your Rails app, they either have Imagemagick installed or it is an option for you to do that manually.
Personally I'd go with something like Heroku, it's easy and the interface is slick and pretty. Here is their setup guide: https://devcenter.heroku.com/articles/rails3

Newly uploaded images break in production but not in development

I would appreciate any feedback regarding what may be causing my issue, described below.
I have an application that allows users to upload images. Everything works fine in development and used to work fine in production.
Recently, my newer images have all broken. I can upload new images, but when I check back a few hours later, the images are broken again. This started happening about a week ago, and images that I've had up in production from before then are still ok.
I am using Rails with Bootstrap and SimpleForm, and using Paperclip for the images. I am using Postgres in both devleopment and production, and am deploying to Heroku.
The only hint I have is in the "blank_profile_pic.png" image that I use as a default when users don't have a profile picture uploaded.
User.all.each do |u|
if u.profile_pic.file?
image_tag(user.profile_pic)
else
image_tag("blank_profile_pic.png")
end
end
For users that don't have a profile_pic uploaded, a broken image appears if their profile was created in the last week, but the expected "blank_profile_pic.png" remains for people that created their account before the issues started surfacing a week ago. How can the same block of code return different results between recent and older users?
I really don't know where to start with this, so would appreciate any feedback regarding what possible causes could be, and if there are any other files that I can show here.
Thanks very much for your help!
Heroku is a read only system. So you most definitely have to upload your images either to S3 or some other cloud provided.
Your images might have been uploaded to /tmp in Heroku and then somehow it was cleared, hence the errors.
Here are the docs: https://devcenter.heroku.com/articles/read-only-filesystem
And configuring Paperclip with S3: https://github.com/thoughtbot/paperclip#storage
I am not sure if you have the imagemagick gem installed, but we had same issue with image_magic that was breaking our paperclip functionality in production, but not in development (weird, I know). Yet even after removing imagemagick from our gemfile and Gemfile.lock locally (running bundle install and all that stuff) and then deploying back to production on heroku, the error persisted in production! (weird, I know).
What ended up doing the trick was running:
$ heroku repo:purge_cache -a myAppName
(Taken from: https://github.com/heroku/heroku-repo#purge_cache)
When you deploy your app, Heroku caches some things like your assets and installed gems in order to speed up deployment. Although this is a great feature, it can have side-effects sometimes, and in this case, it seems that something about the imagemagick gem got "stuck" in production's cache, which is why purging solved the issue for us (since after purging, your app will rebuild itself from scratch on your next deployment)

Rails 3 compatible image uploading with no dependencies?

OK so I'm looking for a good image uploading gem that is Rails 3 compatible and has no dependencies. I was using attachment_fu, but it's Rails 3 compatibility seems to be in question. And I really wanted to use Paperclip, but it has an image majick dependency. I'm having a hard time finding other alternatives...
Stupid question #1: Shouldnt Rails have some "official" image uploading scheme thats baked into the framework? Every web app will need it at some point, and hunting around every time for some questionable third-party way of doing this gets old after awhile.
Stupid question #2: Why can't Paperclip have a no-dependency mode that doesnt make thumbnails or resize, and just stores images as they are uploaded?
As someone who has Rails with Paperclip running on both Linux, Mac and Windows, I can tell you: installing ImageMagic (or whatever spelling is) is not a problem.
In fact, my old linux hosting already had it, Mac laptop, IIRC, too. I expected some problems installing it on windows, but had to just download installer and specify correct path in rails. No problem whatsoever.
So, in your place, I would really give it a try.
edit
There's also a number of file upload plugins for Rails, but I didn't use them and can't really give advice there. Google will give you examples.

Resources