Last active
June 18, 2018 20:36
-
-
Save uldza/6711bc47c823656f97cd to your computer and use it in GitHub Desktop.
Image optim and dragonfly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add gem | |
| https://github.com/toy/image_optim | |
| # For production/demo install instructions look in gem readme | |
| ### UBUNTU 12.04 image_optim requirments: | |
| > sudo add-apt-repository ppa:danmbox/ppa | |
| > sudo apt-get update | |
| > sudo apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush pngquant | |
| # download pngout from http://www.jonof.id.au/kenutils | |
| > wget http://static.jonof.id.au/dl/kenutils/pngout-20130221-linux.tar.gz | |
| > tar -xvf pngout-20130221-linux.tar.gz | |
| # Get your architecture | |
| > uname -a | |
| # Copy correct pngout to /usr/bin | |
| > sudo cp pngout /usr/bin/ | |
| # Install svgo | |
| > sudo npm install -g svgo | |
| ### MAC instal: | |
| > brew install imagemagick --build-from-source | |
| > brew install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush pngquant | |
| > npm install -g svgo | |
| # download pngout from http://www.jonof.id.au/kenutils | |
| # Unzip, copy to /usr/bin | |
| # In dragonfly initializer add (for newer dragonfly check this out: | |
| # https://gist.github.com/bobbus/8913693) | |
| class ImageOptimProcessor | |
| def optim(temp_object) | |
| io = ImageOptim.new | |
| optimized = io.optimize_image(temp_object.path) | |
| tempfile = Tempfile.new('optimized-image') | |
| begin | |
| optimized.copy(tempfile.path) | |
| ensure | |
| tempfile.close | |
| end | |
| optimized.nil? ? temp_object : tempfile | |
| end | |
| end | |
| app = Dragonfly[:images] | |
| app.configure do |c| | |
| c.processor.register(ImageOptimProcessor) | |
| c.job :optim do | |
| process :optim | |
| end | |
| c.job :thumb do |geometry, format| | |
| process :thumb, geometry | |
| process :optim | |
| encode format if format | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment