docxify 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9feb2e005b3722bb91013f2b319a93da1f7ee49cbce3d28491dc279f1a06776a
4
- data.tar.gz: 792b462f78fb7c03dc73f12ef9c9ab9359e55ab09d06a3cbcf10bd65b332cac9
3
+ metadata.gz: 71db0768a21fe9c99eaca1fe8835db8f0619530f3b111fc767afd1bbd15c5da5
4
+ data.tar.gz: 46507a64f582f7f6486556ab68e26baf93a4d3c1353293b0c1aa9068cbe9a0cf
5
5
  SHA512:
6
- metadata.gz: fe9457df0501983598674783c781ebf2cc8b964e540aadc90645d8a1132a62ed0a28c2cbec56931d069b2435cb5e6419cca4a7e4232afb22f0b4a08bac2687ee
7
- data.tar.gz: 0a8d8fb56b6f88350885cb0afadf8100fa31b682c3bef5c1cdba90ce0c039fdb9fc2f00aa3024723c9add5bb7cc97b288378def2f0ccf4ab85287f72d4f65408
6
+ metadata.gz: eaecad61bffa383575bc36536ac8c39d66e745e22fd2b26f509f39325b1faeecb66904ac9184b179e3e27883065ebd7dfe982667bb68c9b6cbdb7dfacb866055
7
+ data.tar.gz: 1bd65897a04c0a22ff34b7d1224c8d39a1421219d4d6e4abf7e187bd14764e493c72fb205a7b4f33699866d1f018d5c420989123b6a05542e57c962acb83721b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.5
4
+
5
+ Bugfix:
6
+
7
+ - Should insert image with correct aspect ratio if only one dimension is specified
8
+
3
9
  ## 0.1.4
4
10
 
5
11
  Bugfix:
@@ -7,7 +7,7 @@ module DocXify
7
7
  JPEG_START = "\xFF\xD8".b.freeze
8
8
  JPEG_END = "\xFF\xD9".b.freeze
9
9
 
10
- attr_accessor :data, :filename
10
+ attr_accessor :data, :filename, :width, :height
11
11
 
12
12
  def initialize(file_path_or_data)
13
13
  super()
@@ -15,16 +15,16 @@ module DocXify
15
15
  end
16
16
 
17
17
  def load_file_data(file_path_or_data)
18
- if ::File.exist?(file_path_or_data)
18
+ if (::File.exist?(file_path_or_data) rescue false)
19
19
  file_path_or_data = ::File.read(file_path_or_data, mode: "rb")
20
20
  end
21
21
 
22
- if contains_png_image?(file_path_or_data)
23
- @data = file_path_or_data
24
- @filename = "#{Digest::SHA1.hexdigest(@data)}.png"
25
- elsif contains_jpeg_image?(file_path_or_data)
26
- @data = file_path_or_data
27
- @filename = "#{Digest::SHA1.hexdigest(@data)}.jpg"
22
+ @data = file_path_or_data
23
+
24
+ if contains_png_image?(data)
25
+ @filename = "#{Digest::SHA1.hexdigest(data)}.png"
26
+ elsif contains_jpeg_image?(data)
27
+ @filename = "#{Digest::SHA1.hexdigest(data)}.jpg"
28
28
  else
29
29
  raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG")
30
30
  end
@@ -1,3 +1,5 @@
1
+ require "image_size"
2
+
1
3
  module DocXify
2
4
  module Element
3
5
  class Image < Base
@@ -9,8 +11,25 @@ module DocXify
9
11
 
10
12
  @align = options[:align] || :left
11
13
  @after = options[:after]
12
- @height_cm = options[:height_cm] || 5
13
- @width_cm = options[:width_cm] || 5
14
+ @height_cm = options[:height_cm]
15
+ @width_cm = options[:width_cm]
16
+
17
+ image_size = ImageSize.new(StringIO.new(file.data))
18
+
19
+ if @height_cm.nil? || @width_cm.nil?
20
+ @width = image_size.width
21
+ @height = image_size.height
22
+ end
23
+
24
+ if @height_cm.nil? && @width_cm.nil?
25
+ @height_cm = 5
26
+ end
27
+
28
+ if @height_cm.nil?
29
+ @height_cm = @width_cm * image_size.height / image_size.width
30
+ elsif @width_cm.nil?
31
+ @width_cm = @height_cm * image_size.width / image_size.height
32
+ end
14
33
  end
15
34
 
16
35
  def id
@@ -1,3 +1,3 @@
1
1
  module DocXify
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docxify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
@@ -11,6 +11,20 @@ bindir: exe
11
11
  cert_chain: []
12
12
  date: 2024-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: image_size
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rubyzip
16
30
  requirement: !ruby/object:Gem::Requirement