toy / image_optim Goto Github PK
View Code? Open in Web Editor NEWOptimize images using multiple utilities
Home Page: https://github.com/toy/image_optim
License: MIT License
Optimize images using multiple utilities
Home Page: https://github.com/toy/image_optim
License: MIT License
I'm having trouble matching the worker names to the tools that need to be installed (is advancecomp related to advpng?). The documentation could be clearer here.
Also, the worker names should all be spelled in the documentation to people can at least deactivate them. Probably even better a section for each, where additional options can be listet.
Keep up the good work! This gem solved a big problem for me.
I serve a lot of SVG images in my designs for resolution independence (esp. logos and illustrations) and am manually compressing them with svgo.
It would be awesome to have this as another worker, has anybody already started an implementation? Any reasons against it?
Thanks!
~ Jonathan
Have you guys considered pngquant
(http://pngquant.org/) as a worker?
https://github.com/thoughtbot/paperclip
module Paperclip
class Optimizer < Processor
def make
Optimizer.optimize_image(@file.path) || @file
end
end
end
Given I already downloaded the osx app, I have a dir with all the needed executables. It would be neat to be able to point image_optim there, instead of having to install them all over again.
I've found jpegmini and tinypng to have better compression results and I'm curious to why that is? I figured these tools all used the same underlying compression libraries. I've tried amping up the image_optim settings, but don't see much difference.
While trying to optimize a picture, image_optim failed because /usr/bin/which was not present on the system. Is it possible that Gem would check if /usr/bin/which exists so that it can install only if this dependency is satisfied?
I'm the author of a gem called spriteful that uses image_optim
to optimize the sprites generated by my gem.
My idea is that spriteful should use any of the available workers in the developer machine, and instead of raising any exceptions it should just skip any missing worker. The problem is that ImageOptim.new
will crash on any missing worker and the only way to avoid that is to do a pre-check of existing workers, which isn't very scalable as each new image_optim
release that brings new workers requires me to update a list of workers on my side.
Do you think that we could have a way to avoid these failures and just let ImageOptim
pick up the available workers? Something like passing a raise: false
option comes to mind - Other alternative would be a static array of the available workers so I wouldn't have to maintain this list by myself.
This error was appearing to me when I installed image_optim dependencies using the tutorial in the wiki:
ImageOptim::BinNotFoundError: `jpegtran` not found
The problem is that in Amazon AMI x86 64bits (The default image for Amazon EC2 instance) the binary jpegtran comes only in the libjpeg-turbo-utils package!
Here is my tutorial for installing the image_optim dependencies on Amazon EC2:
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/advancecomp-1.15-12.el6.x86_64.rpm
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/gifsicle-1.60-1.el6.x86_64.rpm
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/jhead-2.90-2.el6.x86_64.rpm
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/jpegoptim-1.3.0-1.el6.x86_64.rpm
sudo yum install -y libjpeg-turbo libjpeg-turbo-utils
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/optipng-0.6.4-1.el6.x86_64.rpm
sudo yum install -y pngcrush
Cheers
Awesome wrapper for great utils,
I was wondering if there is any logic to skip optimisaion, if there is any that has been done before (like jpeg is progressive already)?
Thanks
It would be nice to be able to specify a configuration file with default options for image_optim.
For example in $HOME/.config/image_optim/settings.conf
no-threads = true
no-pngout = true
verbose = true
It seems like no matter which png I use, I keep receiving the same error. On Ruby 2.1.1 using rvm and Mac OS 10.9.2.
image_optim /Users/xxx/Desktop/png24-interlaced_skyline.png -v
outputs...
verbose: true
Nice level: 10
Using threads: 4
optimizing: ......Resolved pngcrush 1.7.68
β 0.695815s pngcrush -rem alla -reduce -cc -q -- /Users/xxx/Desktop/png24-interlaced_skyline.png /var/folders/by/70n009td6jndv4p6b2t82m4r0000gp/T/png24-interlaced_skyline20140325-12551-16yakln.png
optimizing: ...... (elapsed: 1s)
undefined method 'inject for nil:NilClass
/Users/xxx/.rvm/gems/ruby-2.1.1/gems/image_optim-0.12.1/lib/image_optim/runner.rb:57:in 'run!'
/Users/xxx/.rvm/gems/ruby-2.1.1/gems/image_optim-0.12.1/lib/image_optim/runner.rb:68:in 'run!'
/Users/xxx/.rvm/gems/ruby-2.1.1/gems/image_optim-0.12.1/bin/image_optim:106:in '<top (required)>'
/Users/xxx/.rvm/gems/ruby-2.1.1/bin/image_optim:23:in 'load'
/Users/xxx/.rvm/gems/ruby-2.1.1/bin/image_optim:23:in '
I've attached the image used in this example. Anyone else having a similar issue?
After running image_optim in -r
recursive mode inside of a subversion directory, svn is unable to commit changes, failing with the error "Working copy text base is corrupt". Re-checking out the repository and running image_optim recursively using shell globbing instead doesn't have this issue (eg image_optim **/*.png
)
In verbose mode with -r
, you can see image_optim modifying files inside of the .svn
directories, which is what is probably causing issues. A similar issue may exist for git repos (?)
Hey Ivan,
First thank you so much for your work on this.
Is there a way to target multiple directories or recurse through directories and compress all images within?
Image_optim v 0.11.1 causes:
rake aborted!
pngout
not found
on a debian machine, all packages (advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush) are installed.
ubuntu symlinks /bin/sh to dash so the latest fix to the system call: b6fa79f
doesn't work
this simple changes fixes the error:
teaforthecat@970d7e7
I am assuming this would work on the mac, ?
Would be really nice to have this in windows, all the binaries exist for windows in some form.
Currently I tried setting line 47
of bin_resolver.rb
to true and now all I get is The system cannot find the path specified.
with no traceroute or easy way to debug it.
It's probably because it can't find the .exe files even though they are in PATH
and gems\image_optim-0.10.0\vendor
.
Also bin_resolver.rb
uses symlinks which are not supported in ruby on windows.
Maybe it's possible to extensively patch that one file and fix everything?
If not then I guess windows support may never happen, but I accept that. π’
Check out this article :)
http://psionides.eu/2012/05/06/extending-asset-pipeline-with-custom-preprocessors/
class RootUrlPreprocessor < Sprockets::Processor
def evaluate(context, locals)
data.gsub(%r"\bHOSTNAME\b", "myserver.com")
end
end
The context is an instance of Sprockets::Context; you can use it to e.g. read the current fileβs path or content type, generate paths to asset files or access asset pipeline configuration. You also have access to several asset helpers from ActionView, like javascript_include_tag, image_tag etc.
http://rubydoc.info/gems/sprockets/2.0.3/Sprockets/Context
I think you would need fx content_type
and somehow access the full path of the asset and run it through image_optim.
# in config/initializers/sprockets.rb
Rails.application.assets.register_preprocessor('application/javascript',
RootUrlPreprocessor)
Just found an example here: https://github.com/botandrose/sprockets-image_compressor
Maybe you could join forces ;)
Sweet and simple! Yeah :)
Hey, great work with this gem, however I'm having an issue when deploying it in Production (Ubuntu 14.04). I'm getting:
lib/image_optim/config.rb:13:in `expand_path': couldn't find HOME environment -- expanding `~' (ArgumentError)
My user does have a home directory and when I run console, I get this:
irb(main):002:0> ENV["HOME"]
=> "/home/deployer"
irb(main):003:0> File.expand_path("~")
=> "/home/deployer"
Not sure what's happening.
It would be helpful for debugging, if it's possible to get the file-sizes before and after optimization of a single file (maybe even a percentage diff)
I'm using image_optim via middleman-imageoptim
and when I run it with the following settings,
options.pngout_options = {:copy_chunks => false, :strategy => 1}
options.pngcrush_options = {:chunks => :allb, :fix => false, :brute => false}
options.optipng_options = {:level => 2, :interlace => nil}
options.advpng_options = {:level => 2}
options.jpegoptim_options = {:strip => ['all'], :max_quality => 80}
options.jpegtran_options = {:copy_chunks => false, :progressive => true, :jpegrescan => true}
options.gifsicle_options = {:interlace => false}
and I'm having results that look like this.
But the precompressed images look like this.
I don't understand why they're getting compressed into gray blocks, is there something I'm missing about the optimization settings?
Don't ask me why, but I'm working with a large set of user uploaded photos and they are all stored without the extension.
Since this photos are going to be served through the web, I'm testing some utils to compress those images.
When I call image_optim passing a png without extension, the program prints this output:
image_optim image
optimizing: ...... (elapsed: 0s)
However the above works if the image is actually a jpeg:
image_optim image
optimizing: 100.0% (elapsed: 0s)
46.03% 25.9K image
Total: 46.03% 25.9K
I'm trying to use this on a site, and it works great for images I include in the repository. However, I also have a few sprites that are generated by compass (not checked in to the repo) and it's not optimizing those ones.
I'd be happy to help fix this, but I'm not sure where to start. If anyone can point me in the right direction that would be awesome!
cd /tmp
curl -O http://iweb.dl.sourceforge.net/project/pmt/pngcrush/1.7.70/pngcrush-1.7.70.tar.gz
tar zxf pngcrush-1.7.70.tar.gz
cd pngcrush-1.7.70
make && cp -f pngcrush /usr/local/bin
should change to
cd /tmp
curl -O http://iweb.dl.sourceforge.net/project/pmt/pngcrush/1.7.73/pngcrush-1.7.73.tar.gz
tar zxf pngcrush-1.7.73.tar.gz
cd pngcrush-1.7.73
make && cp -f pngcrush /usr/local/bin
First, thanks for a great lib!
Sometimes in scripts, I already have the imagedata, maybe I've cut up thumbnails for a bigger image or whatever.
It would be nice to be able to optimize that imagedata Without having to first save it to a file so image_optim can read it.
Maybe a new method to not break the current API:
image_optim.optimize_image_data( image_data )
[feature request]
It would be great to be able to pass in a level
param from the CLI interface... which normalized to each of the commands for controlling the level of optimization...
each command has their own levels, but you could offer an abstraction from 1-4 or something and have each of your options maps to something in the spectrum of the other command options.
Option to preserve color profile
io.optimize_image( dragonfly_file.tempfile )
.bundle/ruby/1.9.1/gems/image_optim-0.6.0/lib/image_optim/worker.rb:66:in `reopen': /dev/pts/6 can't change access mode from "r+" to "w" (ArgumentError)
using ruby 1.9.3 on ubuntu 12.04
using dragonfly
trying to follow this gist: https://gist.github.com/3320781
but running in rails console also does not work.
Not sure where to start looking into this error. help?
First of all: Thank you so much for this software.
I can see that ImageOptim now relies on Zopfli that is software from Google. It could be nice to have this integrated as well http://googledevelopers.blogspot.co.uk/2013/02/compress-data-more-densely-with-zopfli.html
I have a strange feeling that compressed files land in /tmp directory. I realised that after one of my rake tasks had been interrupted due to lack of space on a disc.
Command I run (for a large number of images, size around 50 GB):
image_optim = ImageOptim.new(:pngout => false, :pngcrush => false,
:optipng => { :level => 7 }, :advpng => false, :jpegoptim => { :strip => "all" },
:jpegtran => false)
logger = Logger.new("#{Rails.root}/log/image_optim.log")
image_optim.optimize_images!(images) do |unoptimized, optimized|
logger.info("#{Time.now} optimised image: #{unoptimized}") if optimized
end
Is it possible to avoid such behaviour or dump files to /dev/null, or delete them during procesing?
Using a Dragonfly initializer with:
processor :optim do |content|
io = ImageOptim.new(svgo: false)
optimized = io.optimize_image(content.path)
optimized.nil? ? content : optimized
end
Results in:
ImageOptim::BinNotFoundError: `jpegoptim` not found
Running jpegoptim
in the terminal works fine.
Rails 4.1, Ruby 2.1.1, CentOS 6.5, jpegoptim 1.3.1
When attempting to use the recursive command line flags, I am receiving a generic JPEG marker not found
error. This isn't happening in every use case, I believe it's only occurring when a corrupted JPEG is encountered.
EDIT: Upon further inspection, the JPEG does not appear to be corrupted. The header is 24bit N Exif IPTC ICC Adobe JFIF
Actually, the only way to set global config for image_optim
is to write them in a .yml
file.
For our Rails application, this is not really practical and we would like to make it possible to set them in an initializer or application config.
Does it seems like a useful feature ? If so, I can try to write a PR implementing this.
Since 11.1, I get this error when trying to start a rails app that includes this gem.
/Users/aaron/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/image_optim-0.11.1/lib/image_optim/railtie.rb:17:in block in <class:Railtie>': undefined method
register_preprocessor' for nil:NilClass (NoMethodError)
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.