local-fastimage_resize 3.4.0 → 3.4.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 +5 -5
- data/CHANGELOG.md +7 -0
- data/ext/fastimage_native_resize/fastimage_native_resize.c +49 -33
- data/lib/fastimage/resize/version.rb +1 -1
- data/lib/fastimage/resize.rb +5 -2
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4d043392b65693b4af9bca7adc247c1872443e906bf4c72e4e93a37da8b086e
|
4
|
+
data.tar.gz: e1f0da7471e86c33faf6c790a6eabda379c2c6b7bb1029958e8afa296575a08f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af1768186b8a056a5b3cacae9a7d99e2795df3d734522418636fa085c0935f9310245e7c6107b0bafb09db63987eb8421ecc76f3ab14abb3ff7522c790603e6
|
7
|
+
data.tar.gz: a9a22b4b9c6639984209422ea73cb7dbcd13ddf408befb4edb95960226f3400d66cfef1e00c8f491ad44bc6f92ee9f938940fb33a10459893384d4f67dfd252d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 3.4.1 - 2025-03-04
|
2
|
+
|
3
|
+
Improved error handling and memory management to fix segmentation faults that
|
4
|
+
could occur with malformed images.
|
5
|
+
|
6
|
+
Introduced a new `FastImage::Resize::ImageProcessingError` exception class
|
7
|
+
|
1
8
|
# 3.4.0 - 2021-02-10
|
2
9
|
|
3
10
|
Support for resizing TIFF images. Output of such an operation is always a PNG
|
@@ -23,7 +23,9 @@ static VALUE fastimage_native_resize(
|
|
23
23
|
int trans = 0, x = 0, y = 0, f = 0;
|
24
24
|
|
25
25
|
in = fopen(filename_in, "rb");
|
26
|
-
if (!in)
|
26
|
+
if (!in) {
|
27
|
+
rb_raise(rb_eIOError, "Could not open input file: %s", filename_in);
|
28
|
+
}
|
27
29
|
|
28
30
|
switch(image_type) {
|
29
31
|
case 0: im_in = gdImageCreateFromJpeg(in);
|
@@ -31,51 +33,62 @@ static VALUE fastimage_native_resize(
|
|
31
33
|
case 1: im_in = gdImageCreateFromPng(in);
|
32
34
|
break;
|
33
35
|
case 2: im_in = gdImageCreateFromGif(in);
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
for (
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
if (im_in) {
|
37
|
+
trans = gdImageGetTransparent(im_in);
|
38
|
+
/* find a transparent pixel, then turn off transparency
|
39
|
+
so that it copies correctly */
|
40
|
+
if (trans >= 0) {
|
41
|
+
for (x=0; x<gdImageSX(im_in); x++) {
|
42
|
+
for (y=0; y<gdImageSY(im_in); y++) {
|
43
|
+
if (gdImageGetPixel(im_in, x, y) == trans) {
|
44
|
+
f = 1;
|
45
|
+
break;
|
46
|
+
}
|
43
47
|
}
|
48
|
+
if (f) break;
|
44
49
|
}
|
45
|
-
|
50
|
+
gdImageColorTransparent(im_in, -1);
|
51
|
+
if (!f) trans = -1; /* no transparent pixel found */
|
46
52
|
}
|
47
|
-
gdImageColorTransparent(im_in, -1);
|
48
|
-
if (!f) trans = -1; /* no transparent pixel found */
|
49
53
|
}
|
50
54
|
break;
|
51
55
|
case 3: im_in = gdImageCreateFromTiff(in);
|
52
56
|
break;
|
57
|
+
default:
|
58
|
+
fclose(in);
|
59
|
+
rb_raise(rb_eArgError, "Unsupported image type: %d", image_type);
|
53
60
|
}
|
54
61
|
|
62
|
+
fclose(in);
|
55
63
|
if (!im_in) {
|
56
|
-
|
57
|
-
return Qnil;
|
64
|
+
rb_raise(rb_eRuntimeError, "Failed to read image data from: %s", filename_in);
|
58
65
|
}
|
59
66
|
|
60
67
|
|
61
68
|
|
62
69
|
/* Handle orientation */
|
63
70
|
if (orientation == 5 || orientation == 6) {
|
64
|
-
|
71
|
+
gdImagePtr rotated = gdImageRotateInterpolated(im_in, 270.0, 0);
|
72
|
+
gdImageDestroy(im_in);
|
73
|
+
if (!rotated) {
|
74
|
+
rb_raise(rb_eRuntimeError, "Failed to rotate image (orientation %d)", orientation);
|
75
|
+
}
|
76
|
+
im_in = rotated;
|
65
77
|
}
|
66
78
|
if (orientation == 7 || orientation == 8) {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
gdImagePtr rotated = gdImageRotateInterpolated(im_in, 90.0, 0);
|
80
|
+
gdImageDestroy(im_in);
|
81
|
+
if (!rotated) {
|
82
|
+
rb_raise(rb_eRuntimeError, "Failed to rotate image (orientation %d)", orientation);
|
83
|
+
}
|
84
|
+
im_in = rotated;
|
72
85
|
}
|
73
86
|
|
74
87
|
if (orientation == 2 || orientation == 5 || orientation == 7) {
|
75
88
|
gdImageFlipHorizontal(im_in);
|
76
89
|
}
|
77
90
|
if (orientation == 3) {
|
78
|
-
|
91
|
+
gdImageFlipBoth(im_in);
|
79
92
|
}
|
80
93
|
if (orientation == 4) {
|
81
94
|
gdImageFlipVertical(im_in);
|
@@ -100,15 +113,14 @@ static VALUE fastimage_native_resize(
|
|
100
113
|
|
101
114
|
|
102
115
|
im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
|
103
|
-
if (im_out) {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
return Qnil;
|
116
|
+
if (!im_out) {
|
117
|
+
gdImageDestroy(im_in);
|
118
|
+
rb_raise(rb_eRuntimeError, "Failed to create output image buffer");
|
119
|
+
}
|
120
|
+
|
121
|
+
if (image_type == 1) {
|
122
|
+
gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
|
123
|
+
gdImageSaveAlpha(im_out, 1);
|
112
124
|
}
|
113
125
|
|
114
126
|
/* Now copy the original */
|
@@ -117,7 +129,11 @@ static VALUE fastimage_native_resize(
|
|
117
129
|
gdImageSX(im_in), gdImageSY(im_in));
|
118
130
|
|
119
131
|
out = fopen(filename_out, "wb");
|
120
|
-
if (out) {
|
132
|
+
if (!out) {
|
133
|
+
gdImageDestroy(im_in);
|
134
|
+
gdImageDestroy(im_out);
|
135
|
+
rb_raise(rb_eIOError, "Could not open output file: %s", filename_out);
|
136
|
+
}
|
121
137
|
switch(image_type) {
|
122
138
|
case 0: gdImageJpeg(im_out, out, jpeg_quality);
|
123
139
|
break;
|
@@ -134,7 +150,7 @@ static VALUE fastimage_native_resize(
|
|
134
150
|
break;
|
135
151
|
}
|
136
152
|
fclose(out);
|
137
|
-
|
153
|
+
|
138
154
|
gdImageDestroy(im_in);
|
139
155
|
gdImageDestroy(im_out);
|
140
156
|
return Qnil;
|
data/lib/fastimage/resize.rb
CHANGED
@@ -31,6 +31,9 @@ module FastImage::Resize
|
|
31
31
|
|
32
32
|
class FormatNotSupported < FastImage::FastImageException # :nodoc:
|
33
33
|
end
|
34
|
+
|
35
|
+
class ImageProcessingError < FastImage::FastImageException # :nodoc:
|
36
|
+
end
|
34
37
|
|
35
38
|
def self.included(base)
|
36
39
|
base.extend ClassMethods
|
@@ -79,11 +82,11 @@ module FastImage::Resize
|
|
79
82
|
|
80
83
|
FastImage.native_resize(path, file_out.to_s, width.to_i, height.to_i, type_index, jpeg_quality.to_i, orientation)
|
81
84
|
|
82
|
-
raise FastImage::ImageFetchFailure, 'Image could be created' unless File.exist?(file_out.to_s)
|
85
|
+
raise FastImage::ImageFetchFailure, 'Image could not be created' unless File.exist?(file_out.to_s)
|
83
86
|
|
84
87
|
temp_file
|
85
88
|
rescue RuntimeError => e
|
86
|
-
raise FastImage::
|
89
|
+
raise FastImage::Resize::ImageProcessingError, e.message
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local-fastimage_resize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
8
8
|
- Gregor Schmidt (Planio)
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: local-fastimage
|
@@ -110,7 +110,7 @@ homepage: http://github.com/planio-gmbh/local-fastimage_resize
|
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
112
|
metadata: {}
|
113
|
-
post_install_message:
|
113
|
+
post_install_message:
|
114
114
|
rdoc_options: []
|
115
115
|
require_paths:
|
116
116
|
- lib
|
@@ -126,9 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements:
|
128
128
|
- libgd, see www.libgd.org
|
129
|
-
|
130
|
-
|
131
|
-
signing_key:
|
129
|
+
rubygems_version: 3.3.22
|
130
|
+
signing_key:
|
132
131
|
specification_version: 4
|
133
132
|
summary: Local FastImage Resize - Image resizing fast and simple
|
134
133
|
test_files: []
|