You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like Rszr::Image.load_data does not seem to work correctly. Same data blob loads just fine via Rszr::Image.load from a file. Looks like the problem is that Tempfile.create removes the tempfile right after loading the image. But that tempfile is needed for processing image later on.
Following test replicates the issue:
diff --git a/spec/rszr_spec.rb b/spec/rszr_spec.rb
index e5db69d..02216f9 100644
--- a/spec/rszr_spec.rb+++ b/spec/rszr_spec.rb@@ -18,6 +18,12 @@ RSpec.describe 'Rszr' do
expect(Rszr::Image.load_data(RSpec.root.join('images/test.jpg').binread).format).to eq('jpeg')
end
+ it 'loads image from memory' do+ img = Rszr::Image.load_data(RSpec.root.join('images/test.jpg').binread)++ expect(img[1,1]).to have_attributes(green: 93, blue: 112, red: 78)+ end+
it 'loads images with uppercase extension' do
expect(Rszr::Image.load(RSpec.root.join('images/CHUNKY.PNG'))).to be_kind_of(Rszr::Image)
end
A possible solution would be to make a copy of image before temporary file is removed. But this is not good from performance point of view. On the other hand, is there a better solution? The other way would be to leave temporary file around till OS cleans it up. Which may take up a lot of space during mass image processing.
diff --git a/lib/rszr/image.rb b/lib/rszr/image.rb
index db6d14d..73061fd 100644
--- a/lib/rszr/image.rb+++ b/lib/rszr/image.rb@@ -20,7 +20,7 @@ module Rszr
def load_data(data, autorotate: Rszr.autorotate, **opts)
raise LoadError, 'Unknown format' unless format = identify(data)
with_tempfile(format, data) do |file|
- load(file.path, autorotate: autorotate, **opts)+ load(file.path, autorotate: autorotate, **opts).dup
end
end
The text was updated successfully, but these errors were encountered:
Thank you for reporting and looking into this issue. As of v1.4.0, imlib_load_image_immediately_without_cache is used for loading images from tempfile data.
Looks like
Rszr::Image.load_data
does not seem to work correctly. Same data blob loads just fine viaRszr::Image.load
from a file. Looks like the problem is thatTempfile.create
removes the tempfile right after loading the image. But that tempfile is needed for processing image later on.Following test replicates the issue:
A possible solution would be to make a copy of image before temporary file is removed. But this is not good from performance point of view. On the other hand, is there a better solution? The other way would be to leave temporary file around till OS cleans it up. Which may take up a lot of space during mass image processing.
The text was updated successfully, but these errors were encountered: