diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 04:54:20 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 04:54:20 +0200 |
| commit | b138f40a6493f7c4341fba196c48440e795babb9 (patch) | |
| tree | 957e3945b709542ca744bedf8c54d36a33292c16 | |
| parent | 5f56fa867f073d8d1aecbfbba4a340ea414cfb0d (diff) | |
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.
| -rw-r--r-- | lib/tasks/assets.rake | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ | |||
| 1 | namespace :assets do | ||
| 2 | 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." | ||
| 3 | task :regenerate_variants => :environment do | ||
| 4 | scope = Asset.images | ||
| 5 | scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present? | ||
| 6 | |||
| 7 | scope.find_each do |asset| | ||
| 8 | original_path = asset.send(:file_path, :original) | ||
| 9 | |||
| 10 | unless File.exist?(original_path) | ||
| 11 | puts "Skipping Asset##{asset.id} (#{asset.name}) -- no original file at #{original_path}" | ||
| 12 | next | ||
| 13 | end | ||
| 14 | |||
| 15 | asset.send(:generate_variants, original_path) | ||
| 16 | puts "Regenerated variants for Asset##{asset.id} (#{asset.name})" | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | ||
