Created
September 26, 2023 15:16
-
-
Save GesJeremie/50d9d26bdc6bcfa771d23dda8f172c63 to your computer and use it in GitHub Desktop.
Revisions
-
GesJeremie created this gist
Sep 26, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ require 'mini_magick' namespace :covers do def covers_path Rails.root.join('app', 'assets', 'images', 'covers') end def files_inside_covers_path Dir.glob(covers_path.to_s << '/**/*').select { |path| File.file?(path) } end def covers files_inside_covers_path.reject { |path| path.include?('_thumbnail') } end def thumbnails files_inside_covers_path.select { |path| path.include?('_thumbnail') } end desc 'Generate thumbnails versions of existing covers' task :create_thumbnails do covers.each do |cover_path| destination_path = cover_path.gsub('.jpg', '_thumbnail.jpg') MiniMagick::Image.open(cover_path).tap do |cover| cover.resize('32%') cover.write(destination_path) end end end desc 'Delete thumbnails versions of existing covers' task :destroy_thumbnails do thumbnails.each do |thumbnail_path| File.delete(thumbnail_path) end end end