diff options
| author | Ken D'Ambrosio <ken@jots.org> | 2026-06-18 23:00:17 +0000 |
|---|---|---|
| committer | Ken D'Ambrosio <ken@jots.org> | 2026-06-18 23:00:17 +0000 |
| commit | 6f975533f075cc761184b5a7392522264eca6fc1 (patch) | |
| tree | 33b1f8678d34331a5b9b6a358ca688467263ec0b /app.rb | |
| parent | faec9c5448dfe3bbb7e187c7fb4d58557b70035d (diff) | |
Many older photos (especially pre-EXIF-orientation cameras) are off
by a multiple of 90 degrees with no metadata to auto-correct. Each
image row in the admin file table now has rotate buttons that
physically rotate the file (auto-orienting first to normalize any
existing EXIF tag), swap the stored width/height, and clear the
cached thumbnail so it regenerates from the corrected image.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'app.rb')
| -rw-r--r-- | app.rb | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -702,6 +702,43 @@ def save_edits(rel, dir) atomic_write(File.join(dir, 'album.json'), JSON.pretty_generate(data)) end +post '/admin/rotate/' do + require_admin! + rotate_file('', MEDIA_ROOT) +end + +post '/admin/rotate/*' do + require_admin! + rel = params[:splat].first.chomp('/') + rotate_file(rel, resolve_dir(rel)) +end + +def rotate_file(rel, dir) + name = File.basename(params[:file].to_s) + full = File.join(dir, name) + halt 404 unless File.file?(full) + halt 400 unless IMAGE_EXTS.include?(File.extname(name).downcase.delete_prefix('.')) + + degrees = params[:dir] == 'left' ? -90 : 90 + img = MiniMagick::Image.open(full) + img.combine_options do |c| + c.auto_orient + c.rotate degrees + end + img.write(full) + + data = load_album(dir) + data['files'] ||= {} + meta = (data['files'][name] ||= {}) + meta['width'], meta['height'] = meta['height'], meta['width'] if meta['width'] && meta['height'] + atomic_write(File.join(dir, 'album.json'), JSON.pretty_generate(data)) + + thumb = thumb_cache_path(rel.empty? ? name : "#{rel}/#{name}") + File.unlink(thumb) if File.exist?(thumb) + + redirect "/admin/edit/#{rel}" +end + # ── Background update ───────────────────────────────────────────────────────── post '/admin/update' do |
