lizard 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/colorspaces/CMYK/CoatedFOGRA27.icc +0 -0
  3. data/colorspaces/CMYK/CoatedFOGRA39.icc +0 -0
  4. data/colorspaces/CMYK/CoatedGRACoL2006.icc +0 -0
  5. data/colorspaces/CMYK/ISOcoated_v2_300_eci.icc +0 -0
  6. data/colorspaces/CMYK/JapanColor2001Coated.icc +0 -0
  7. data/colorspaces/CMYK/JapanColor2001Uncoated.icc +0 -0
  8. data/colorspaces/CMYK/JapanColor2002Newspaper.icc +0 -0
  9. data/colorspaces/CMYK/JapanColor2003WebCoated.icc +0 -0
  10. data/colorspaces/CMYK/JapanWebCoated.icc +0 -0
  11. data/colorspaces/CMYK/USWebCoatedSWOP.icc +0 -0
  12. data/colorspaces/CMYK/USWebUncoated.icc +0 -0
  13. data/colorspaces/CMYK/UncoatedFOGRA29.icc +0 -0
  14. data/colorspaces/CMYK/WebCoatedFOGRA28.icc +0 -0
  15. data/colorspaces/CMYK/WebCoatedSWOP2006Grade3.icc +0 -0
  16. data/colorspaces/CMYK/WebCoatedSWOP2006Grade5.icc +0 -0
  17. data/colorspaces/Color Profile Bundling License_10.15.08.pdf +0 -0
  18. data/colorspaces/Profile Information.pdf +0 -0
  19. data/colorspaces/RGB/AdobeRGB1998.icc +0 -0
  20. data/colorspaces/RGB/AppleRGB.icc +0 -0
  21. data/colorspaces/RGB/ColorMatchRGB.icc +0 -0
  22. data/colorspaces/RGB/PAL_SECAM.icc +0 -0
  23. data/colorspaces/RGB/SMPTE-C.icc +0 -0
  24. data/colorspaces/RGB/VideoHD.icc +0 -0
  25. data/colorspaces/RGB/VideoNTSC.icc +0 -0
  26. data/colorspaces/RGB/VideoPAL.icc +0 -0
  27. data/colorspaces/RGB/sRGB_IEC61966-2-1_no_black_scaling.icc +0 -0
  28. data/colorspaces/RGB/sRGB_v4_ICC_preference.icc +0 -0
  29. data/colorspaces/Trademark Information.pdf +0 -0
  30. data/lib/lizard.rb +16 -0
  31. data/lib/lizard/color.rb +22 -0
  32. data/lib/lizard/color_profiles.rb +10 -0
  33. data/lib/lizard/error.rb +12 -0
  34. data/lib/lizard/histogram.rb +24 -0
  35. data/lib/lizard/image.rb +85 -0
  36. data/lib/lizard/version.rb +3 -0
  37. metadata +79 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e61377b87baa780930681ab9a2a270f3c5446ca4
4
+ data.tar.gz: 98770224e4aeb9f75ec7fc11aafe4f3f1694f184
5
+ SHA512:
6
+ metadata.gz: c694fd18380abcbfdf58ded15f14c6991b041a8f6eb910fedf62a118498580c117c660a5cfd2ba3710d09daf25d96d982ead0110074eed9d5d4d905f968d21ae
7
+ data.tar.gz: 2998c50c993a9eceefb752da2840b77a84935082b56fa0c58b93cfb6dab89d99f18f857cdf602e35c75bf0a251d90829b9fb40b9231615dea0f21262271777b9
@@ -0,0 +1,16 @@
1
+ require 'open3'
2
+
3
+ module Lizard
4
+
5
+ def self.root
6
+ File.expand_path('../../', __FILE__)
7
+ end
8
+
9
+ def self.run_command(command, input = nil)
10
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
11
+ stdin.write(input) if input
12
+ stdin.close
13
+ [stdout.read, stderr.read, wait_thr.value.to_i]
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
1
+ module Lizard
2
+ class Color
3
+ attr_reader :frequency, :hex
4
+
5
+ def initialize(frequency, hex)
6
+ @frequency = frequency
7
+ @hex = hex
8
+ end
9
+
10
+ def red
11
+ @hex[0,2].to_i(16)
12
+ end
13
+
14
+ def green
15
+ @hex[2,2].to_i(16)
16
+ end
17
+
18
+ def blue
19
+ @hex[4,2].to_i(16)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'lizard'
2
+
3
+ module Lizard
4
+
5
+ COLOR_PROFILES = {
6
+ 'CMYK' => File.join(root, 'colorspaces', 'CMYK', 'CoatedFOGRA39.icc'),
7
+ 'RGB' => File.join(root, 'colorspaces', 'RGB', 'sRGB_IEC61966-2-1_no_black_scaling.icc')
8
+ }
9
+
10
+ end
@@ -0,0 +1,12 @@
1
+ module Lizard
2
+
3
+ class Error < StandardError
4
+ end
5
+
6
+ class NotAnImage < Error
7
+ end
8
+
9
+ class ResizeFailed < Error
10
+ end
11
+
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'lizard/color'
2
+ module Lizard
3
+ class Histogram
4
+
5
+ def initialize(data)
6
+ stdout, stderr, exit_code = Lizard.run_command("convert - -colors 16 -depth 8 -format %c histogram:info:-", data)
7
+ if exit_code == 0
8
+ stdout = stdout.split(/\n/)
9
+ @colors = stdout.each_with_object(Array.new) do |line, colors|
10
+ if line =~ /\A\s*(\d+)\:.*\#([A-F0-9]{6}).*\z/
11
+ colors << Color.new($1.to_i, $2)
12
+ end
13
+ end.sort_by(&:frequency)
14
+ else
15
+ raise Error, "Could not get histogram"
16
+ end
17
+ end
18
+
19
+ def colors
20
+ @colors ||= []
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,85 @@
1
+ require 'tempfile'
2
+ require 'lizard/color_profiles'
3
+ require 'lizard/error'
4
+ require 'lizard/histogram'
5
+
6
+ module Lizard
7
+ class Image
8
+
9
+ def self.is_image?(data)
10
+ image = Image.new(data)
11
+ true
12
+ rescue NotAnImage
13
+ false
14
+ end
15
+
16
+ def initialize(data)
17
+ @data = data
18
+ @properties = identify
19
+ end
20
+
21
+ def data
22
+ @data
23
+ end
24
+
25
+ def type
26
+ @properties[:type]
27
+ end
28
+
29
+ def resolution
30
+ @properties[:resolution]
31
+ end
32
+
33
+ def width
34
+ @properties[:width].to_i
35
+ end
36
+
37
+ def height
38
+ @properties[:height].to_i
39
+ end
40
+
41
+ def color_space
42
+ @properties[:color_space].strip
43
+ end
44
+
45
+ def color_model
46
+ case color_space
47
+ when/CMYK/i then 'CMYK'
48
+ when /RGB/i then 'RBG'
49
+ else nil
50
+ end
51
+ end
52
+
53
+ def resize(width, height)
54
+ size = "#{width}x#{height}\\>"
55
+ profile = "-profile " + Lizard::COLOR_PROFILES['RGB']
56
+ if self.color_model == 'CMYK'
57
+ profile = "-profile " + COLOR_PROFILES[self.color_model].to_s + " " + profile
58
+ end
59
+ stdout, stderr, exit_code = Lizard.run_command("convert - -flatten #{profile} -resize #{size} -", @data)
60
+ if exit_code == 0
61
+ Image.new(stdout)
62
+ else
63
+ raise ResizeFailed, "Image could not be resized (#{stderr})"
64
+ end
65
+ end
66
+
67
+ def histogram
68
+ @histogram ||= Histogram.new(@data)
69
+ end
70
+
71
+ private
72
+
73
+ def identify
74
+ stdout, stderr, exit_code = Lizard.run_command(%Q{identify -format "Lizard||%m||%[resolution.x]x%[resolution.y]||%wx%h||%r" -}, @data)
75
+ if exit_code == 0 && stdout =~ /\ALizard\|\|/
76
+ _, type, resolution, size, color_space = stdout.split("||")
77
+ width, height = size.split('x')
78
+ {:type => type, :resolution => resolution, :width => width, :height => height, :size => size, :color_space => color_space}
79
+ else
80
+ raise NotAnImage, stderr
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Lizard
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lizard
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Very simple ImageMagick interface for Ruby
14
+ email:
15
+ - me@adamcooke.io
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - colorspaces/CMYK/CoatedFOGRA27.icc
21
+ - colorspaces/CMYK/CoatedFOGRA39.icc
22
+ - colorspaces/CMYK/CoatedGRACoL2006.icc
23
+ - colorspaces/CMYK/ISOcoated_v2_300_eci.icc
24
+ - colorspaces/CMYK/JapanColor2001Coated.icc
25
+ - colorspaces/CMYK/JapanColor2001Uncoated.icc
26
+ - colorspaces/CMYK/JapanColor2002Newspaper.icc
27
+ - colorspaces/CMYK/JapanColor2003WebCoated.icc
28
+ - colorspaces/CMYK/JapanWebCoated.icc
29
+ - colorspaces/CMYK/USWebCoatedSWOP.icc
30
+ - colorspaces/CMYK/USWebUncoated.icc
31
+ - colorspaces/CMYK/UncoatedFOGRA29.icc
32
+ - colorspaces/CMYK/WebCoatedFOGRA28.icc
33
+ - colorspaces/CMYK/WebCoatedSWOP2006Grade3.icc
34
+ - colorspaces/CMYK/WebCoatedSWOP2006Grade5.icc
35
+ - colorspaces/Color Profile Bundling License_10.15.08.pdf
36
+ - colorspaces/Profile Information.pdf
37
+ - colorspaces/RGB/AdobeRGB1998.icc
38
+ - colorspaces/RGB/AppleRGB.icc
39
+ - colorspaces/RGB/ColorMatchRGB.icc
40
+ - colorspaces/RGB/PAL_SECAM.icc
41
+ - colorspaces/RGB/SMPTE-C.icc
42
+ - colorspaces/RGB/VideoHD.icc
43
+ - colorspaces/RGB/VideoNTSC.icc
44
+ - colorspaces/RGB/VideoPAL.icc
45
+ - colorspaces/RGB/sRGB_IEC61966-2-1_no_black_scaling.icc
46
+ - colorspaces/RGB/sRGB_v4_ICC_preference.icc
47
+ - colorspaces/Trademark Information.pdf
48
+ - lib/lizard.rb
49
+ - lib/lizard/color.rb
50
+ - lib/lizard/color_profiles.rb
51
+ - lib/lizard/error.rb
52
+ - lib/lizard/histogram.rb
53
+ - lib/lizard/image.rb
54
+ - lib/lizard/version.rb
55
+ homepage: https://github.com/adamcooke/lizard
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Very simple ImageMagick interface for Ruby
79
+ test_files: []