lib/cheesy-gallery/image_file.rb in cheesy-gallery-1.1.0 vs lib/cheesy-gallery/image_file.rb in cheesy-gallery-1.1.1

- old
+ new

@@ -1,22 +1,20 @@ -# typed: strict # frozen_string_literal: true require 'rmagick' require 'cheesy-gallery/base_image_file' # This StaticFile subclass adds additional functionality for images in the # gallery class CheesyGallery::ImageFile < CheesyGallery::BaseImageFile - @@geometry_cache = T.let(Jekyll::Cache.new('CheesyGallery::Geometry'), Jekyll::Cache) # don't need to worry about inheritance here # rubocop:disable Style/ClassVars + @@geometry_cache = Jekyll::Cache.new('CheesyGallery::Geometry') # don't need to worry about inheritance here # rubocop:disable Style/ClassVars - sig { params(site: Jekyll::Site, collection: Jekyll::Collection, file: Jekyll::StaticFile, max_size: String, quality: Integer).void } def initialize(site, collection, file, max_size:, quality:) super(site, collection, file) - @max_size = T.let(max_size, String) - @quality = T.let(quality, Integer) + @max_size = max_size + @quality = quality realpath = File.realdirpath(path) mtime = File.mtime(realpath) geom = @@geometry_cache.getset("#{realpath}##{mtime}") do result = [100, 100] @@ -33,11 +31,10 @@ data['height'] = geom[0] data['width'] = geom[1] end # instead of copying, renders an optimised version - sig { params(img: Magick::ImageList, path: String).void } def process_and_write(img, path) img.change_geometry!(@max_size) do |cols, rows, i| i.resize!(cols, rows) end # follow recommendations from https://stackoverflow.com/a/7262050/4918 to get better compression @@ -45,8 +42,8 @@ # but skip the blur to avoid too many changes to the data # img.gaussian_blur(0.05) img.strip! # workaround weird {self} initialisation pattern quality = @quality - img.write(path) { self.quality = quality } + img.write(path) { |image| image.quality = quality } end end