minimagick

Get image dimensions using Refile

拈花ヽ惹草 提交于 2019-12-04 05:53:11
Using the Refile gem to handle file uploading in Rails, what is the best way to determine image height and width during / after it has been uploaded? There is no built in support for this AFAIK, and I can't figure out how to do it using MiniMagick. Mike V @russellb's comment almost got me there, but wasn't quite correct. If you have a Refile::File called @file, you need to: fileIO = @file.to_io.to_io mm = MiniMagick::Image.open(fileIO) mm.width # image width mm.height # image height Yes, that's two calls to #to_io >...< The first to_io gives you a Tempfile, which isn't what MiniMagick wants.

Carrierwave: Scale image if the size is larger than (conditionally create versions)

本秂侑毒 提交于 2019-12-03 17:30:00
Is possible with carrierwave create a version (for example thumb) only if the image is larger than the size of the version?? Example: version :thumb, :if => :is_thumbnable? do process :resize_to_fit => [32,nil] end protected def is_thumbnable?(file) image ||= MiniMagick::Image.open(file.path) if image.nil? if image['width'] >= 32 || image['height'] >= 32 true else false end else false end end I defined method in which if image exceed given width then manipulate it to your size the 32 pixels in this case. Put this code in your ImageUploader: version :thumb do process :resize_to_width => [32,

Rails 5.2 ActiveStorage save and then read Exif data

筅森魡賤 提交于 2019-12-02 01:30:11
问题 On Rails 5.2 I am trying to save an avatar via ActiveStorage but it seems as though not image oriantation data is being saved in the active storage blob. I am saving the avatar via a file_field on a create action my #user model has_one_attached :avatar private def avatar_validation if avatar.attached? if avatar.blob.byte_size > 1000000 avatar.purge errors.add(:avatar, 'file is too large') elsif !avatar.blob.content_type.in?(%w[image/png image/jpg image/jpeg]) avatar.purge errors.add(:avatar,

Rails 5.2 ActiveStorage save and then read Exif data

99封情书 提交于 2019-12-01 21:11:53
On Rails 5.2 I am trying to save an avatar via ActiveStorage but it seems as though not image oriantation data is being saved in the active storage blob. I am saving the avatar via a file_field on a create action my #user model has_one_attached :avatar private def avatar_validation if avatar.attached? if avatar.blob.byte_size > 1000000 avatar.purge errors.add(:avatar, 'file is too large') elsif !avatar.blob.content_type.in?(%w[image/png image/jpg image/jpeg]) avatar.purge errors.add(:avatar, 'file type needs to be JPEG, JPG, or PNG') end end end I have been reading some documentation for

mini_magick gem doesn't work with my ImageMagick install

馋奶兔 提交于 2019-12-01 10:42:07
I have the ImageMagick installed via MacPorts and the mini_magick gem and I get an error for the following script. How can I resolve this problem? require 'rubygems' require 'mini_magick' image = MiniMagick::Image.open("input.jpg") image.resize "100x100" image.write "output.jpg" /Users/Max/.rvm/gems/ruby-1.9.3-p125/gems/mini_magick-3.4/lib/mini_magick.rb:164:in `create': MiniMagick::Invalid (MiniMagick::Invalid) from /Users/Max/.rvm/gems/ruby-1.9.3-p125/gems/mini_magick-3.4/lib/mini_magick.rb:73:in `read' from /Users/Max/.rvm/gems/ruby-1.9.3-p125/gems/mini_magick-3.4/lib/mini_magick.rb:134:in

mini_magick gem doesn't work with my ImageMagick install

不羁岁月 提交于 2019-12-01 09:06:21
问题 I have the ImageMagick installed via MacPorts and the mini_magick gem and I get an error for the following script. How can I resolve this problem? require 'rubygems' require 'mini_magick' image = MiniMagick::Image.open("input.jpg") image.resize "100x100" image.write "output.jpg" /Users/Max/.rvm/gems/ruby-1.9.3-p125/gems/mini_magick-3.4/lib/mini_magick.rb:164:in `create': MiniMagick::Invalid (MiniMagick::Invalid) from /Users/Max/.rvm/gems/ruby-1.9.3-p125/gems/mini_magick-3.4/lib/mini_magick.rb

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

我怕爱的太早我们不能终老 提交于 2019-11-30 08:39:31
I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu . Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools installed. Running: $ brew doctor # Your system is raring to brew. I can upload and resize images in this configuration: rails 3.1.4 ruby 1.8.7 carrierwave 0.5.8 mini_magick 3.4 I can upload images in the new configuration: rails 3.2.3 ruby 1.9.3 (or 1.9.2) carrierwave 0.6.2 (followed by $ bundle update ) but resizing using mini_magick returns this

Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3

戏子无情 提交于 2019-11-30 03:19:19
I was having a heck of a time getting this to work, and still am. I'll get to the heart of it. I'm following Ryan Bates tutorial to make cropping work using Jcrop and Carrierwave. I've opted to use MiniMagick because even after reinstalling ImageMagick and RMagick on my machine I get an error that kills the rails server on my local machine. Anyway switching to MiniMagick fixed that for me. So everything is really nice up until this point. I have different sized images being produced, and they're being uploaded successfully. But once I try to crop I get this error: undefined method `crop!' for

Carrierwave Error Msg: Failed to manipulate with MiniMagick, maybe it is not an image?

笑着哭i 提交于 2019-11-29 12:19:11
问题 I am upgrading my app to Rails 3.2 on Ruby 1.9. I had to drop attachment_fu . Carrierwave seemed the obvious replacement. At this stage I am uploading files to the file system (no cloud files, yet). I am on Lion, XCode 4.3.2, Command Line Tools installed. Running: $ brew doctor # Your system is raring to brew. I can upload and resize images in this configuration: rails 3.1.4 ruby 1.8.7 carrierwave 0.5.8 mini_magick 3.4 I can upload images in the new configuration: rails 3.2.3 ruby 1.9.3 (or 1

Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3

早过忘川 提交于 2019-11-29 00:59:14
问题 I was having a heck of a time getting this to work, and still am. I'll get to the heart of it. I'm following Ryan Bates tutorial to make cropping work using Jcrop and Carrierwave. I've opted to use MiniMagick because even after reinstalling ImageMagick and RMagick on my machine I get an error that kills the rails server on my local machine. Anyway switching to MiniMagick fixed that for me. So everything is really nice up until this point. I have different sized images being produced, and they