sdsykes / fastimage_resize Goto Github PK
View Code? Open in Web Editor NEWFastImage Resize is an extremely light solution for resizing images in ruby by using libgd
License: MIT License
FastImage Resize is an extremely light solution for resizing images in ruby by using libgd
License: MIT License
Excellent gem! MiniMagick was too slow for on-the-fly resizes and this really speeded things up!
One thing that'd be useful is the ability to read from streams (an object responding to #read). Currently I need to save database files to disk, resize them to a new path on disk and lastly open the resized_path and return it (File.open(path_written_by_fastimage_resize)
).
In our Rails project we want to use the gem local-fastimage_resize which requires libgd
. According to the doc (and the Internet) it should be possible to install it by means of homebrew
but when we try to install the gem it can't find the library.
Here are some logs from my M1 mac:
$ brew info libgd
==> gd: stable 2.3.3 (bottled), HEAD
Graphics library to dynamically manipulate images
https://libgd.github.io/
/opt/homebrew/Cellar/gd/2.3.3_3 (33 files, 1.5MB) *
Poured from bottle on 2022-10-10 at 12:18:49
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gd.rb
License: Cannot Represent
==> Dependencies
Required: fontconfig ✔, freetype ✔, jpeg-turbo ✔, libavif ✔, libpng ✔, libtiff ✔, webp ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 147,026 (30 days), 503,823 (90 days), 1,624,252 (365 days)
install-on-request: 17,867 (30 days), 55,417 (90 days), 144,616 (365 days)
build-error: 0 (30 days)
$ gem install local-fastimage_resize -- --with-gdlib=/opt/homebrew/Cellar/gd/2.3.3_3
Building native extensions with: '--with-gdlib=/opt/homebrew/Cellar/gd/2.3.3_3'
This could take a while...
ERROR: Error installing local-fastimage_resize:
ERROR: Failed to build gem native extension.
current directory: /Users/jgallaso/.asdf/installs/ruby/2.6.8/lib/ruby/gems/2.6.0/gems/local-fastimage_resize-3.4.0/ext/fastimage_native_resize
/Users/jgallaso/.asdf/installs/ruby/2.6.8/bin/ruby -I /Users/jgallaso/.asdf/installs/ruby/2.6.8/lib/ruby/2.6.0 -r ./siteconf20221010-18826-otaeca.rb extconf.rb --with-gdlib\=/opt/homebrew/Cellar/gd/2.3.3_3
checking for -l/opt/homebrew/Cellar/gd/2.3.3_3... no
missing libgd
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/jgallaso/.asdf/installs/ruby/2.6.8/bin/$(RUBY_BASE_NAME)
--with-gdlib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/jgallaso/.asdf/installs/ruby/2.6.8/lib/ruby/gems/2.6.0/extensions/arm64-darwin-21/2.6.0/local-fastimage_resize-3.4.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/jgallaso/.asdf/installs/ruby/2.6.8/lib/ruby/gems/2.6.0/gems/local-fastimage_resize-3.4.0 for inspection.
Results logged to /Users/jgallaso/.asdf/installs/ruby/2.6.8/lib/ruby/gems/2.6.0/extensions/arm64-darwin-21/2.6.0/local-fastimage_resize-3.4.0/gem_make.out
I've also tried installing libgd manually following instructions in INSTALL but no matter the path --with-gdlib
it will return the same error.
Any ideas? 😖
/usr/lib/ruby/vendor_ruby/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'fastimage_resize'. (Bundler::GemRequireError)
this error showing even i am installed this gem
I have tried many different images (png and jpg) and the output image after resize is always 96dpi when the original images were al 72dpi. Any thoughts on why this could be?
Get a: uninitialized constant RAILS_ROOT
what worked for me:
ENV['INLINEDIR'] = Rails.root.join("tmp").to_s # for RubyInline
Hello
Running on ruby 1.9.2 + rails 3.1.2, i got Encoding::UndefinedConversionError exception when calling FastImage.resize.
Dug in, and found that filemode is not binary.
workaround - added
temp.binmode
to fastimage_resize.rb :: read_to_local
New method code:
def self.read_to_local(readable)
temp = Tempfile.new(name)
temp.binmode # <--
temp.write(readable.read)
temp.close
temp.open
temp
end
The gem works fine on my localhost, but it doesn't work on Heroku, because libgd2 isn't supported by them anymore. (https://devcenter.heroku.com/articles/cedar-ubuntu-packages). Can you help with this issue?
Example image: https://www.magazin-hp.ru/image/cache/catalog/06_server/hp-server-power/hp_power_460W_001-600x600.png
GD Error: gd-png: fatal libpng error: Read Error: truncated data
GD Warning: gd-png error: setjmp returns error condition 2
/home/maroki/.rvm/gems/ruby-2.3.4/gems/fastimage_resize-2.0.3/lib/fastimage_resize.rb:90: [BUG] Segmentation fault at 0x0000000000000c
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0048 p:---- s:0215 e:000214 CFUNC :resize_image
c:0047 p:0308 s:0206 e:000205 METHOD /home/maroki/.rvm/gems/ruby-2.3.4/gems/fastimage_resize-2.0.3/lib/fastimage_resize.rb:90
c:0046 p:0020 s:0190 e:000189 EVAL (pry):1 [FINISH]
c:0045 p:---- s:0188 e:000187 CFUNC :eval
Ran in to some weirdness with resized images just now. They occurred after updating to 2.0.0 and when I jumped back to 1.2.4 the problem disappeared. Similar problems with a bunch of photos, but I've only included one of them here.
http://imageshack.us/photo/my-images/855/originalxh.jpg/
http://imageshack.us/photo/my-images/839/resize250x200.jpg/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.