Giter VIP home page Giter VIP logo

image_optim's Issues

Compressed files land in /tmp

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?

undefined method `inject' for nil:NilClass when using pngcrush

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 '

'
/Users/xxx/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in 'eval'
/Users/xxx/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in ''

I've attached the image used in this example. Anyone else having a similar issue?

png24-interlaced_skyline

SVG compression?

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

Rails 4 compatibility

Config assets.compress is removed in Rails 4.

It is actually used here

I would propose to remove this check and only look on app.config.assets.image_optim value.

@toy , if you agree, I can try a PR for this.

`pngout` not found, linux

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.

Can't detect file type without extension on pngs

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

PNG files getting "over-optimized" into gray blocks.

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.

logo_affiliate-amegy-bank-b983eb36

But the precompressed images look like this.

logo_affiliate-amegy-bank

I don't understand why they're getting compressed into gray blocks, is there something I'm missing about the optimization settings?

ImageOptim::BinNotFoundError: `jpegoptim` not found

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

Recursive directories via command line

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?

Optimized PNG looks a lot different

Running into a quirk where ImageOptim changes one of my PNGs during its optimization process. I don't fully understand why it's doing this.

I could ignore the specific file, but I actually do want it optimized. Just looking for some clues on what the problem is.

logo

can't change access mode of IO object with zeus

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?

Ignore Bin resolving errors programatically

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.

Improve documentation

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.

couldn't find HOME environment

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.

Not as good as online compression tools

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.

Windows support

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. 😒

Optimize from raw image data, not a file

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 )

Integration with Rails asset pipeline as sprocket preprocessor

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 :)

Add configuration file

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

JPEG marker not found error when using recursive

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

level parameter from CLI?

[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.

Compass sprite support

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!

Running recursively in an svn repo directory corrupts the repository

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 (?)

undefined method `register_preprocessor'

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 methodregister_preprocessor' for nil:NilClass (NoMethodError)

Add global configuration from Ruby

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.

ImageOptim::BinNotFoundError: `jpegtran` not found

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

parameter for binary path

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.