FEATURE: correctly store width and height on uploads

Previously we used width and height for thumbnails, new code ensures

1. We auto correct width and height
2. We added extra columns for thumbnail_width and height, this is determined
 by actual upload and no longer passed in as a side effect
3. Optimized Image now stores filesize which can be used for analysis, decisions

Also

- fixes Android image manifest as a side effect
- fixes issue where a thumbnail generated that is smaller than the upload is no longer used
This commit is contained in:
Sam
2018-08-28 12:48:43 +10:00
parent 1826626272
commit 9ab1fb7dfc
11 changed files with 159 additions and 25 deletions

View File

@@ -54,22 +54,35 @@ describe OptimizedImage do
end
it 'should work correctly' do
tmp_path = "/tmp/resized.png"
begin
OptimizedImage.resize(
"#{Rails.root}/spec/fixtures/images/logo.png",
tmp_path,
5,
5
)
file = File.open("#{Rails.root}/spec/fixtures/images/resized.png")
upload = UploadCreator.new(file, "test.bin").create_for(-1)
expect(File.read(tmp_path)).to eq(
File.read("#{Rails.root}/spec/fixtures/images/resized.png")
)
ensure
File.delete(tmp_path) if File.exists?(tmp_path)
end
expect(upload.filesize).to eq(199)
expect(upload.width).to eq(5)
expect(upload.height).to eq(5)
upload.create_thumbnail!(10, 10)
thumb = upload.thumbnail(10, 10)
expect(thumb.width).to eq(10)
expect(thumb.height).to eq(10)
# very image magic specific so fudge here
expect(thumb.filesize).to be > 200
# this size is based off original upload
# it is the size we render, by default, in the post
expect(upload.thumbnail_width).to eq(5)
expect(upload.thumbnail_height).to eq(5)
# lets ensure we can rebuild the filesize
thumb.update_columns(filesize: nil)
thumb = OptimizedImage.find(thumb.id)
# attempts to auto correct
expect(thumb.filesize).to be > 200
end
describe 'when an svg with a href is masked as a png' do