kt-paperclip-mozjpeg 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54fb888dcb82bca77a493443cd9fdbdd53396416a58fc94f242ef41c06f3e7db
4
+ data.tar.gz: 5b111ae746be0847e51c1855934ce40115d18b6cfb8015bd36692dcb703fd0c7
5
+ SHA512:
6
+ metadata.gz: 63aa878a623b7990ed3d1a2ce624dc32bafe6b35bc11199aac34de001b9ec11607ff73a564717b706888775e734c4c994f856db71f4f6bd629811a5f9e4394dd
7
+ data.tar.gz: 4b655615ccee1b3601e954d945a2998768095b7fb4c8d7b1608b947826af16bb78714ea55f9c3909e8705f5935c1beac88a5ce73d9f87c602a53f3c92d29f961
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-mozjpeg.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # About
2
+
3
+ This repository contains the ruby library which adds file processor to compress JPEG images uploaded using the [paperclip](https://github.com/thoughtbot/paperclip) gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'paperclip-mozjpeg'
11
+
12
+ # To use bundled binaries of MozJPEG 3.0 for Mac OS X, Linux and Windows add:
13
+ gem 'mozjpeg'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install paperclip-mozjpeg
23
+
24
+ To install bundled binaries (must `require 'mozjpeg'` if not using bundler):
25
+
26
+ $ gem install mozjpeg
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ class User < ActiveRecord::Base
32
+ has_attached_file :avatar, :styles => {
33
+ :tiny => {
34
+ geometry: '190x190>',
35
+ mozjpeg_options: '-quality 30',
36
+ },
37
+ :large => {
38
+ geometry: '1280x1280>',
39
+ mozjpeg_options: '-quality 70 -quant-table 2 -notrellis',
40
+ }
41
+ },
42
+ processors: [ :thumbnail, :mozjpeg ]
43
+ end
44
+ ```
45
+
46
+ If you don't want to use the `mozjpeg` gem bundled binaries and want to specify the path to mozjpeg (cjpeg) or it is not in the `PATH` use the `mozjpeg_path` option.
47
+
48
+
49
+ ## License
50
+
51
+ This gem is licensed under the MIT license.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/svoboda-jan/paperclip-mozjpeg/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "paperclip/mozjpeg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ require "paperclip-mozjpeg/version"
2
+ require 'paperclip'
3
+
4
+ module Paperclip
5
+
6
+ # Handles JPEG and PNG compression.
7
+ class Mozjpeg < Processor
8
+
9
+ attr_accessor :whiny, :mozjpeg_options
10
+
11
+ # Compresses the +file+ using MozJPEG's cjpeg command.
12
+ # Compression will raise no errors unless +whiny+ is true
13
+ # (which it is, by default).
14
+ #
15
+ # Options include:
16
+ #
17
+ # +geometry+ - the desired width and height of the thumbnail (required)
18
+ # +whiny+ - whether to raise an error when processing fails. Defaults to true
19
+ def initialize(file, options = {}, attachment = nil)
20
+ super
21
+ @geometry = options[:geometry].to_s
22
+ @mozjpeg_options = options[:mozjpeg_options]
23
+ @whiny = options.fetch(:whiny, true)
24
+ @use_system_binaries = options.fetch(:use_system_binaries, false)
25
+ @mozjpeg_path = options.fetch(:mozjpeg_path, nil)
26
+ @current_format = File.extname(@file.path)
27
+ @basename = File.basename(@file.path, @current_format)
28
+ end
29
+
30
+ # Performs the compression of the +file+. Returns the Tempfile
31
+ # that contains the new image.
32
+ def make
33
+ src = @file
34
+ filename = [@basename, @format ? ".#{@format}" : ""].join
35
+ dst = TempfileFactory.new.generate(filename)
36
+
37
+ begin
38
+ parameters = []
39
+ parameters << mozjpeg_options
40
+ parameters << "-outfile :dest"
41
+ parameters << ":source"
42
+
43
+ parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
44
+
45
+ success = cjpeg(parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
46
+ # dynamic exception handling to support paperclip using Cocaine or Terrapin gem
47
+ rescue Class.new { def self.===(ex); ex.class.name.end_with?("::ExitStatusError"); end }
48
+ raise Paperclip::Error, "There was an error processing the file for #{@basename}" if @whiny
49
+ rescue Class.new { def self.===(ex); ex.class.name.end_with?("::CommandNotFoundError"); end }
50
+ raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `cjpeg` command. Please install MozJPEG.")
51
+ end
52
+
53
+ dst
54
+ end
55
+
56
+ def cjpeg(arguments = "", local_options = {})
57
+ if !@use_system_binaries && defined?(::Mozjpeg::VERSION)
58
+ cmd = ::Mozjpeg.cjpeg_path
59
+ end
60
+ cmd ||= ( @mozjpeg_path || 'cjpeg')
61
+ Paperclip.run(cmd, arguments, local_options)
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module PaperclipMozjpeg
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paperclip-mozjpeg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "#{ENV["GEM_NAME_PREFIX"]+"-" if ENV["GEM_NAME_PREFIX"]}paperclip-mozjpeg"
8
+ spec.version = PaperclipMozjpeg::VERSION
9
+ spec.authors = ["Jan Svoboda"]
10
+ spec.email = ["jan@mluv.cz"]
11
+
12
+ spec.summary = %q{JPEG and PNG compression processor for paperclip using MozJPEG.}
13
+ spec.description = %q{JPEG and PNG compression processor for paperclip using MozJPEG.}
14
+ spec.homepage = "https://github.com/svoboda-jan/paperclip-mozjpeg"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 1.9"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+
26
+ spec.add_development_dependency "minitest", "~> 5.4.2"
27
+
28
+ spec.add_dependency "#{ENV["GEM_NAME_PREFIX"]+"-" if ENV["GEM_NAME_PREFIX"]}paperclip"
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kt-paperclip-mozjpeg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jan Svoboda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.4.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.4.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: kt-paperclip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: JPEG and PNG compression processor for paperclip using MozJPEG.
70
+ email:
71
+ - jan@mluv.cz
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/paperclip-mozjpeg.rb
84
+ - lib/paperclip-mozjpeg/version.rb
85
+ - paperclip-mozjpeg.gemspec
86
+ homepage: https://github.com/svoboda-jan/paperclip-mozjpeg
87
+ licenses: []
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '1.9'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.1.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: JPEG and PNG compression processor for paperclip using MozJPEG.
108
+ test_files: []