docxify 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/docxify/element/file.rb +8 -10
- data/lib/docxify/element/image.rb +21 -2
- data/lib/docxify/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71db0768a21fe9c99eaca1fe8835db8f0619530f3b111fc767afd1bbd15c5da5
|
4
|
+
data.tar.gz: 46507a64f582f7f6486556ab68e26baf93a4d3c1353293b0c1aa9068cbe9a0cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaecad61bffa383575bc36536ac8c39d66e745e22fd2b26f509f39325b1faeecb66904ac9184b179e3e27883065ebd7dfe982667bb68c9b6cbdb7dfacb866055
|
7
|
+
data.tar.gz: 1bd65897a04c0a22ff34b7d1224c8d39a1421219d4d6e4abf7e187bd14764e493c72fb205a7b4f33699866d1f018d5c420989123b6a05542e57c962acb83721b
|
data/CHANGELOG.md
CHANGED
data/lib/docxify/element/file.rb
CHANGED
@@ -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,18 +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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
elsif contains_jpeg_image?(
|
27
|
-
@
|
28
|
-
@filename = "#{Digest::SHA1.hexdigest(@data)}.jpg"
|
29
|
-
puts "Contains JPEG image #{@filename}"
|
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"
|
30
28
|
else
|
31
29
|
raise ArgumentError.new("Unsupported file type - images must be PNG or JPEG")
|
32
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]
|
13
|
-
@width_cm = options[:width_cm]
|
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
|
data/lib/docxify/version.rb
CHANGED
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
|
+
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
|