peasy-image 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/peasy_image/engine.rb +54 -0
- data/lib/peasy_image/version.rb +5 -0
- data/lib/peasy_image.rb +4 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cc8e9b67b149980274f8a20ac8571532e6b6e811c07a4afb0612188df07e86c2
|
|
4
|
+
data.tar.gz: 100c9b47f4a8cb3a1213cd77835dbb65ac49822b4e5c7dff794274a5abd14627
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ec0faba71cb2afb60840f09ed253d7285803ac6dc0ca25cae6cabd86a28d1667b2ebaad70da1f8e6cee875a2e16753855c8bd005b4fda54ebdd3b8ab50b0708f
|
|
7
|
+
data.tar.gz: 4d3bb8f3b035e809da6f40d04f9bb90b72f224cf07671cf92c8d988a76c73f8da3a3454b10a9bbb9270b394dbc55dd7fc6698ac1d1cf38d792c28bc847e094bc
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module PeasyImage
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def info(path)
|
|
10
|
+
out, err, st = Open3.capture3("identify", "-format", "%w %h %m %b", path.to_s)
|
|
11
|
+
raise Error, "identify failed: #{err}" unless st.success?
|
|
12
|
+
parts = out.strip.split
|
|
13
|
+
{ width: parts[0].to_i, height: parts[1].to_i, format: parts[2], size: parts[3] }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def resize(input, width:, height: nil, output: nil)
|
|
17
|
+
output ||= input.to_s.sub(/(\.\w+)$/, "_resized\\1")
|
|
18
|
+
geom = height ? "#{width}x#{height}" : "#{width}x"
|
|
19
|
+
_o, err, st = Open3.capture3("convert", input.to_s, "-resize", geom, output)
|
|
20
|
+
raise Error, "resize failed: #{err}" unless st.success?
|
|
21
|
+
output
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def crop(input, width:, height:, x: 0, y: 0, output: nil)
|
|
25
|
+
output ||= input.to_s.sub(/(\.\w+)$/, "_cropped\\1")
|
|
26
|
+
geom = "#{width}x#{height}+#{x}+#{y}"
|
|
27
|
+
_o, err, st = Open3.capture3("convert", input.to_s, "-crop", geom, "+repage", output)
|
|
28
|
+
raise Error, "crop failed: #{err}" unless st.success?
|
|
29
|
+
output
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def convert(input, format:, output: nil)
|
|
33
|
+
output ||= input.to_s.sub(/\.\w+$/, ".#{format}")
|
|
34
|
+
_o, err, st = Open3.capture3("convert", input.to_s, output)
|
|
35
|
+
raise Error, "convert failed: #{err}" unless st.success?
|
|
36
|
+
output
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def compress(input, quality: 80, output: nil)
|
|
40
|
+
output ||= input.to_s.sub(/(\.\w+)$/, "_compressed\\1")
|
|
41
|
+
_o, err, st = Open3.capture3("convert", input.to_s, "-quality", quality.to_s, output)
|
|
42
|
+
raise Error, "compress failed: #{err}" unless st.success?
|
|
43
|
+
output
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def rotate(input, degrees: 90, output: nil)
|
|
47
|
+
output ||= input.to_s.sub(/(\.\w+)$/, "_rotated\\1")
|
|
48
|
+
_o, err, st = Open3.capture3("convert", input.to_s, "-rotate", degrees.to_s, output)
|
|
49
|
+
raise Error, "rotate failed: #{err}" unless st.success?
|
|
50
|
+
output
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class Error < StandardError; end
|
|
54
|
+
end
|
data/lib/peasy_image.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: peasy-image
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- PeasyTools
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Image processing library for Ruby — resize, crop, compress, convert between
|
|
13
|
+
formats, and add watermarks. Uses ImageMagick/GraphicsMagick via system CLI.
|
|
14
|
+
email:
|
|
15
|
+
- hello@peasytools.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/peasy_image.rb
|
|
21
|
+
- lib/peasy_image/engine.rb
|
|
22
|
+
- lib/peasy_image/version.rb
|
|
23
|
+
homepage: https://peasyimage.com
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://peasyimage.com
|
|
28
|
+
source_code_uri: https://github.com/peasytools/peasy-image-rb
|
|
29
|
+
changelog_uri: https://github.com/peasytools/peasy-image-rb/blob/main/CHANGELOG.md
|
|
30
|
+
documentation_uri: https://peasyimage.com
|
|
31
|
+
bug_tracker_uri: https://github.com/peasytools/peasy-image-rb/issues
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements: []
|
|
46
|
+
rubygems_version: 4.0.3
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Image processing — resize, crop, compress, convert, watermark
|
|
49
|
+
test_files: []
|