carrierwave-optimize-image 1.0.1

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: 4e69bcec68d3064a231ab49f79eea883f5099ffe9af0dd5edeca04c49d5c552a
4
+ data.tar.gz: '088fa1e9ee14a793d128b9c5e361b4488703d7086bc011bf3f7d24da21c6d036'
5
+ SHA512:
6
+ metadata.gz: 25b6338553b7aff4c21e1ecd90c9a8ed31b9fb7ff629722c54776d92b841682399258b3bd5087146acd36f257f920164014cc7cc12c595f7469d0e5c51501387
7
+ data.tar.gz: 1691dd5c60e79224bead534106cbe46a195d52ce85e48c0ba41bd396d10689ac4a2b5e600af2dd32013e061e30d9265f1c6a077f1ff377e2033f8f47385c1e43
@@ -0,0 +1,44 @@
1
+ module CarrierWave
2
+ module OptimzeImage
3
+ def optimize(options = {})
4
+ @level = options[:level].present? ? options[:level].to_i : 30
5
+ begin
6
+
7
+ if check_file_format?
8
+ lossless_ffmpeg_compression
9
+ end
10
+
11
+ rescue Exception => e
12
+ puts e
13
+ end
14
+ end
15
+
16
+ def check_file_format?
17
+ if file.content_type.include?("gif") || file.content_type.include?("video")
18
+ false
19
+ else
20
+ true
21
+ end
22
+ end
23
+
24
+ def lossless_ffmpeg_compression
25
+ create_temp_image
26
+ end
27
+
28
+ def create_temp_image
29
+ tempfile = Tempfile.new(["#{file.filename}_#{Time.current.to_i}", File.extname(file.path)])
30
+ tempfile.binmode
31
+ tempfile.write(to_blob)
32
+ ffmpeg(tempfile)
33
+ tempfile.unlink
34
+ end
35
+
36
+ def to_blob
37
+ File.binread(file.path)
38
+ end
39
+
40
+ def ffmpeg(tempfile)
41
+ system(" ffmpeg -y -i #{tempfile.path} -q:v #{@level} #{current_path}")
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-optimize-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Quaranto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
27
+ description: A Simple gem that use ffmpeg library to compress images in carrierwave
28
+ gem.
29
+ email: nick@quaran.to
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/carrierwave-optimize-image.rb
35
+ homepage: https://rubygems.org/gems/hola
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.7.6
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: optimizaton of images
59
+ test_files: []