![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
PaperclipOptimizer is a Paperclip processor for optimizing and minifying uploaded images.
It is just a thin wrapper around ImageOptim, which supports many external optimization libraries such as advpng, gifsicle, jhead, jpegoptim, jpeg-recompress, jpegtran, optipng, pngcrush, pngout, pngquant and svgo.
2015-01-16 2.0.0
better configuration: set options globally, per attachment and per style
Thanks to danschultzer, braindeaf and tirdadc for pull requests, input and reports
all available optimization libraries are disabled by default
Previous versions enabled jpegtran and optipng by default. You will have to re-enable them manually if you wish to retain that behaviour
optimizers which are enabled but missing or broken are ignored by default
Read the CHANGELOG for previous changes.
PaperclipOptimizer is currently compatible with Paperclip 3.4.2 up to 4.2.x.
Add this line to your application's Gemfile after the Paperclip gem:
gem 'paperclip-optimizer'
And then execute:
$ bundle
If you wish to set global configuration settings, run
$ rails generate paperclip_optimizer:install
to generate an initializer in config/initializers.
image_optim automatically inserts itself into the asset pipeline and tries to compress your /app/assets/images
as well.
Since it enables all libraries it supports by default, you might suddenly run into errors if you do not have all
of them installed.
Please note: settings you made through PaperclipOptimizer only apply to Paperclip attachments, not to image_optims asset compressor.
To disable image_optim in your asset pipeline, add
# config/application.rb
config.assets.image_optim = false
to your config/application.rb.
See ImageOptims README on how to install the various optimization libraries.
If you deploy to Heroku, take a look at the image_optim_bin gem. It supplies the necessary optimization binaries, compiled and ready for Herokus environment.
gem "image_optim_bin", group: :production
gem "paperclip-optimizer"
Just add :paperclip_optimizer
to Paperclips' :processors
- setting:
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
styles: { thumb: "100x100>" },
processors: [:thumbnail, :paperclip_optimizer]
end
Remember to include the :thumbnail
processor as well if you want to retain
Paperclips geometry functionality.
You can pass configuration options to ImageOptim in three locations: globally, per attachment and per style. Settings are merged, so more specific settings replace less specific ones.
Global settings
Global settings apply everywhere. You can override them with per-attachment and per-style settings.
Run rails generate paperclip_optimizer:install
to create an initializer for global settings.
# config/initializers/paperclip_optimizer.rb
Paperclip::PaperclipOptimizer.default_options = {
skip_missing_workers: false
}
Per-attachment settings
Per-attachment settings apply to all styles of a particular attachment. Override them with per-style settings.
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
processors: [:thumbnail, :paperclip_optimizer],
paperclip_optimizer: {
pngout: { strategy: 1 }
},
styles: {
thumb: { geometry: "100x100>" },
medium: { geometry: "200x200>" },
large: { geometry: "300x300>" }
}
end
Just like Paperclips' :styles
option, you can pass a lambda to :paperclip_optimizer
to configure it at runtime:
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
processors: [:thumbnail, :paperclip_optimizer],
paperclip_optimizer: ->(attachment) { attachment.instance.my_model_instance_method },
styles: {
thumb: { geometry: "100x100>" },
medium: { geometry: "200x200>" },
large: { geometry: "300x300>" }
}
end
Per-style settings
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
processors: [:thumbnail, :paperclip_optimizer],
paperclip_optimizer: {
pngout: { strategy: 1 }
},
styles: {
thumb: { geometry: "100x100>" },
medium: { geometry: "200x200>" },
large: {
geometry: "300x300>",
paperclip_optimizer: {
pngout: { strategy: 4 }
}
}
}
end
See ImageOptims options or the initializer for all available options.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that paperclip-optimizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.