From b138f40a6493f7c4341fba196c48440e795babb9 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 13 Jul 2026 04:54:20 +0200 Subject: Add assets:regenerate_variants rake task Regenerates ImageMagick variants from each asset's stored original -- needed because assets uploaded before :headline existed in FileAttachment::STYLES never had that file generated, producing a 404 rather than a distorted image. Supports ASSET_ID=N scoping so a single asset can be tested before committing to a full, expensive sweep across everything. Doesn't touch the separate, still-open problem of :headline's forced non-uniform stretch (460x250!) -- this task faithfully regenerates whatever geometry the style defines, correctly. Fixing the distortion itself is its own, later piece. --- lib/tasks/assets.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/tasks/assets.rake (limited to 'lib') diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake new file mode 100644 index 0000000..563dfad --- /dev/null +++ b/lib/tasks/assets.rake @@ -0,0 +1,19 @@ +namespace :assets do + desc "Regenerate ImageMagick variants for every image asset from its stored original -- rerun whenever a new style is added to FileAttachment::STYLES after assets already exist. Scope to one asset first with ASSET_ID=123." + task :regenerate_variants => :environment do + scope = Asset.images + scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present? + + scope.find_each do |asset| + original_path = asset.send(:file_path, :original) + + unless File.exist?(original_path) + puts "Skipping Asset##{asset.id} (#{asset.name}) -- no original file at #{original_path}" + next + end + + asset.send(:generate_variants, original_path) + puts "Regenerated variants for Asset##{asset.id} (#{asset.name})" + end + end +end -- cgit v1.3