local-fastimage_resize 3.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a7a5852a9c12e9eb1da31bc031d8b39556025aa14a3df7cd21e63c23fe022c0
4
- data.tar.gz: d5cb5920f6434683f56bb828cfb6b4dcd1742ae28e6184fe7b9e559cd2a61947
3
+ metadata.gz: d4d043392b65693b4af9bca7adc247c1872443e906bf4c72e4e93a37da8b086e
4
+ data.tar.gz: e1f0da7471e86c33faf6c790a6eabda379c2c6b7bb1029958e8afa296575a08f
5
5
  SHA512:
6
- metadata.gz: 6d60ea4c09f3901652548da85b723ea6b48959ec60a0633823e1b2a7a05a4318da716b36839d39bd2d9a7521eb3296e1eee459e9849df68c5359844d1c764d1d
7
- data.tar.gz: 8f145aeae41f9e0cfb9aec8d56bc7b5a7b9beddec9d5d31496268434f247bd99dcd3a9c74c5e7a62b36d035dc3a78897faa232a90585fc886fa841d453a595fe
6
+ metadata.gz: 4af1768186b8a056a5b3cacae9a7d99e2795df3d734522418636fa085c0935f9310245e7c6107b0bafb09db63987eb8421ecc76f3ab14abb3ff7522c790603e6
7
+ data.tar.gz: a9a22b4b9c6639984209422ea73cb7dbcd13ddf408befb4edb95960226f3400d66cfef1e00c8f491ad44bc6f92ee9f938940fb33a10459893384d4f67dfd252d
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.10
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
3
+ - 2.4.10
4
+ - 2.5.8
5
+ - 2.6.6
6
+ - 2.7.2
7
+ - 3.0.0
7
8
 
8
9
  before_install:
9
10
  - gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
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
+
8
+ # 3.4.0 - 2021-02-10
9
+
10
+ Support for resizing TIFF images. Output of such an operation is always a PNG
11
+ image.
12
+
1
13
  # 3.3.0 - 2018-04-24
2
14
 
3
15
  Support for Exif orientation.
@@ -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) return Qnil;
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,49 +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
- trans = gdImageGetTransparent(im_in);
35
- /* find a transparent pixel, then turn off transparency
36
- so that it copies correctly */
37
- if (trans >= 0) {
38
- for (x=0; x<gdImageSX(im_in); x++) {
39
- for (y=0; y<gdImageSY(im_in); y++) {
40
- if (gdImageGetPixel(im_in, x, y) == trans) {
41
- f = 1;
42
- break;
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
- if (f) break;
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;
55
+ case 3: im_in = gdImageCreateFromTiff(in);
56
+ break;
57
+ default:
58
+ fclose(in);
59
+ rb_raise(rb_eArgError, "Unsupported image type: %d", image_type);
51
60
  }
52
61
 
62
+ fclose(in);
53
63
  if (!im_in) {
54
- fclose(in);
55
- return Qnil;
64
+ rb_raise(rb_eRuntimeError, "Failed to read image data from: %s", filename_in);
56
65
  }
57
66
 
58
67
 
59
68
 
60
69
  /* Handle orientation */
61
70
  if (orientation == 5 || orientation == 6) {
62
- im_in = gdImageRotateInterpolated(im_in, 270.0, 0);
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;
63
77
  }
64
78
  if (orientation == 7 || orientation == 8) {
65
- im_in = gdImageRotateInterpolated(im_in, 90.0, 0);
66
- }
67
- if (!im_in) {
68
- fclose(in);
69
- return Qnil;
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;
70
85
  }
71
86
 
72
87
  if (orientation == 2 || orientation == 5 || orientation == 7) {
73
88
  gdImageFlipHorizontal(im_in);
74
89
  }
75
90
  if (orientation == 3) {
76
- gdImageFlipBoth(im_in);
91
+ gdImageFlipBoth(im_in);
77
92
  }
78
93
  if (orientation == 4) {
79
94
  gdImageFlipVertical(im_in);
@@ -98,15 +113,14 @@ static VALUE fastimage_native_resize(
98
113
 
99
114
 
100
115
  im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
101
- if (im_out) {
102
- if (image_type == 1) {
103
- gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
104
- gdImageSaveAlpha(im_out, 1);
105
- }
106
- fclose(in);
107
- } else {
108
- fclose(in);
109
- 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);
110
124
  }
111
125
 
112
126
  /* Now copy the original */
@@ -115,7 +129,11 @@ static VALUE fastimage_native_resize(
115
129
  gdImageSX(im_in), gdImageSY(im_in));
116
130
 
117
131
  out = fopen(filename_out, "wb");
118
- 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
+ }
119
137
  switch(image_type) {
120
138
  case 0: gdImageJpeg(im_out, out, jpeg_quality);
121
139
  break;
@@ -128,9 +146,11 @@ static VALUE fastimage_native_resize(
128
146
  }
129
147
  gdImageGif(im_out, out);
130
148
  break;
149
+ case 3: gdImagePng(im_out, out);
150
+ break;
131
151
  }
132
152
  fclose(out);
133
- }
153
+
134
154
  gdImageDestroy(im_in);
135
155
  gdImageDestroy(im_out);
136
156
  return Qnil;
@@ -2,6 +2,6 @@
2
2
 
3
3
  class FastImage
4
4
  module Resize
5
- VERSION = "3.3.0"
5
+ VERSION = "3.4.1"
6
6
  end
7
7
  end
@@ -26,11 +26,14 @@ require 'fastimage'
26
26
  require 'fastimage_native_resize'
27
27
 
28
28
  module FastImage::Resize
29
- SUPPORTED_FORMATS = [:jpeg, :png, :gif]
30
- FILE_EXTENSIONS = [:jpg, :png, :gif] # prefer jpg to jpeg as an extension
29
+ SUPPORTED_FORMATS = [:jpeg, :png, :gif, :tiff]
30
+ FILE_EXTENSIONS = [:jpg, :png, :gif, :tiff] # prefer jpg to jpeg as an extension
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::ImageFetchFailure, e.message
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.3.0
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: 2018-04-24 00:00:00.000000000 Z
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
- rubyforge_project:
130
- rubygems_version: 2.7.6
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: []