neofiles 1.0.6 → 1.1.0
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 +4 -4
- data/app/controllers/neofiles/images_controller.rb +39 -38
- data/app/models/neofiles/image.rb +3 -0
- data/lib/neofiles.rb +4 -0
- data/lib/neofiles/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e96aa097e34ac97047248c698a3aeb9b64bc9ab
|
4
|
+
data.tar.gz: 66851a10940c7c14edd2eef83354815c857328e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d781c8139d2f9618f10a5b32f13b195053c722e3a3c5c4b38068870a780ecffe10dc801f63f73f26d6b532c96bd7f6273e350f8ba4f97d30c992aa9f197825
|
7
|
+
data.tar.gz: 348b856a3802607b95ab7f0df75b1ed4ed2270e1c82965969134417d3cbf03dd49f6cd99a7ddb6925a64fc2c1a021dcf841824efaad085dc5c0c99eb741aa373
|
@@ -54,21 +54,25 @@ class Neofiles::ImagesController < ActionController::Metal
|
|
54
54
|
raise Mongoid::Errors::DocumentNotFound unless width.between?(1, CROP_MAX_WIDTH) and height.between?(1, CROP_MAX_HEIGHT)
|
55
55
|
end
|
56
56
|
|
57
|
-
crop_requested
|
58
|
-
|
57
|
+
crop_requested = Neofiles.crop_requested? params
|
58
|
+
resizing = width && height
|
59
|
+
need_resize_without_crop = resizing && (image_file.width > width || image_file.height > height)
|
59
60
|
|
60
|
-
image.combine_options do |
|
61
|
-
resize_image
|
62
|
-
|
61
|
+
image.combine_options('convert') do |convert|
|
62
|
+
resize_image convert, width, height, crop_requested, need_resize_without_crop if resizing
|
63
|
+
|
64
|
+
unless nowm?(image_file)
|
65
|
+
wm_width, wm_height = Neofiles::resized_image_dimensions image_file, width, height, params
|
66
|
+
add_watermark convert, image, wm_width, wm_height if wm_width && wm_height
|
67
|
+
end
|
68
|
+
|
69
|
+
compress_image convert, quality if quality || resizing
|
63
70
|
end
|
64
71
|
|
65
|
-
# use pngquant when quality less than 75
|
72
|
+
# use pngquant when quality is less than 75
|
66
73
|
::PngQuantizator::Image.new(image.path).quantize! if options[:type] == 'image/png' && quality && quality < 75
|
67
74
|
|
68
|
-
|
69
|
-
width, height = image_file.width, image_file.height if !crop_requested && !need_resize_without_crop
|
70
|
-
|
71
|
-
data = set_watermark(image, image_file, width, height)
|
75
|
+
data = image.to_blob
|
72
76
|
|
73
77
|
# stream image headers & bytes
|
74
78
|
send_file_headers! options
|
@@ -80,6 +84,8 @@ class Neofiles::ImagesController < ActionController::Metal
|
|
80
84
|
self.response_body = I18n.t 'neofiles.403_access_denied'
|
81
85
|
self.content_type = 'text/plain; charset=utf-8'
|
82
86
|
self.status = 403
|
87
|
+
ensure
|
88
|
+
image.try :destroy! #delete mini_magick tempfile
|
83
89
|
end
|
84
90
|
|
85
91
|
|
@@ -100,42 +106,37 @@ class Neofiles::ImagesController < ActionController::Metal
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
|
-
# Fill
|
104
|
-
def resize_image(
|
109
|
+
# Fill convert command pipe with resize commands
|
110
|
+
def resize_image(convert, width, height, crop_requested, need_resize_without_crop)
|
105
111
|
if crop_requested
|
106
|
-
|
107
|
-
|
108
|
-
|
112
|
+
convert.resize "#{width}x#{height}^"
|
113
|
+
convert.gravity 'center'
|
114
|
+
convert.extent "#{width}x#{height}"
|
109
115
|
elsif need_resize_without_crop
|
110
|
-
|
116
|
+
convert.resize "#{width}x#{height}"
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
# Fill
|
120
|
+
# Fill convert command pipe with compression commands for JPEG and PNG
|
115
121
|
# More information: https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/
|
116
|
-
def compress_image(
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
122
|
+
def compress_image(convert, quality)
|
123
|
+
convert.quality "#{quality}" if quality
|
124
|
+
convert << '-unsharp' << '0.25x0.25+8+0.065'
|
125
|
+
convert << '-dither' << 'None'
|
126
|
+
#convert << '-posterize' << '136' # posterize slows down imagamagick extremely in some env due to buggy libgomp1
|
127
|
+
convert << '-define' << 'jpeg:fancy-upsampling=off'
|
128
|
+
convert << '-define' << 'png:compression-filter=5'
|
129
|
+
convert << '-define' << 'png:compression-level=9'
|
130
|
+
convert << '-define' << 'png:compression-strategy=1'
|
131
|
+
convert << '-define' << 'png:exclude-chunk=all'
|
132
|
+
convert << '-interlace' << 'none'
|
133
|
+
convert << '-colorspace' << 'sRGB'
|
134
|
+
convert.strip
|
129
135
|
end
|
130
136
|
|
131
|
-
#
|
132
|
-
def
|
133
|
-
Rails.application.config.neofiles.watermarker.
|
134
|
-
image,
|
135
|
-
no_watermark: nowm?(image_file),
|
136
|
-
watermark_width: width,
|
137
|
-
watermark_height: height
|
138
|
-
)
|
137
|
+
# Add watermarks command to a command pipe, if watermarker is present
|
138
|
+
def add_watermark(convert, image, width, height)
|
139
|
+
Rails.application.config.neofiles.watermarker.try :call, convert, image, width, height
|
139
140
|
end
|
140
141
|
|
141
142
|
end
|
@@ -94,6 +94,9 @@ class Neofiles::Image < Neofiles::File
|
|
94
94
|
tempfile.close
|
95
95
|
tempfile.unlink
|
96
96
|
end
|
97
|
+
|
98
|
+
ensure
|
99
|
+
image.try :destroy! #delete mini_magick tempfile
|
97
100
|
end
|
98
101
|
|
99
102
|
# Return array with width & height decorated with singleton function to_s returning 'WxH' string.
|
data/lib/neofiles.rb
CHANGED
@@ -52,8 +52,12 @@ module Neofiles
|
|
52
52
|
image_file_height = image_file[:height]
|
53
53
|
end
|
54
54
|
|
55
|
+
# no input, terminate
|
55
56
|
return if image_file_width.blank? || image_file_height.blank?
|
56
57
|
|
58
|
+
# image fits into requested dimensions, no resizing will occur
|
59
|
+
return image_file_width, image_file_height if image_file_width <= width && image_file_height <= height
|
60
|
+
|
57
61
|
# ... construct request ...
|
58
62
|
command = MiniMagick::CommandBuilder.new(:convert) # convert input file...
|
59
63
|
command.size([image_file_width, image_file_height].join 'x') # with the given dimensions...
|
data/lib/neofiles/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neofiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konanykhin Ilya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|