Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ImageMagick as an image source #71

Open
SmilyOrg opened this issue Jul 11, 2023 · 4 comments
Open

Support ImageMagick as an image source #71

SmilyOrg opened this issue Jul 11, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@SmilyOrg
Copy link
Owner

Is your feature request related to a problem? Please describe.
Current image sources (native Go, JPEG thumbnails, FFmpeg, ...) do not support all the various popular formats out there, the biggest one being HEIC, which is widely used for iPhone photos (see #52).

Describe the solution you'd like
Add optional support for decoding images with imagemagick. There is a mostly complete implementation already in main...imagemagick, but I wasn't super happy with usability yet, so it might need more work?

Describe alternatives you've considered
https://www.libvips.org/ might be another good one that supports many formats, including HEIC.

Additional context
N/A

@SmilyOrg SmilyOrg moved this to In Progress in Photofield Jul 11, 2023
@SmilyOrg SmilyOrg added the enhancement New feature or request label Jul 11, 2023
@dukobpa3
Copy link

@SmilyOrg
Copy link
Owner Author

Thanks for the heads up! I've considered bimg, but haven't tested it very much yet.

I quite like that the current build is CGo-free, but I'm not opposed to having an optimized "production" build that can make use of libvips, especially if it can be faster at decoding. I don't have a lot of energy to mess with C builds 😅

@dukobpa3
Copy link

I also discovered yesterday that ffmpeg can scale and decode images also :)

ffmpeg -i input_image.cr2 -filter_complex \
"[0:v]scale=1080:-1[1080p]; \
 [0:v]scale=720:-1[720p]; \
 [0:v]scale=480:-1[480p]; \
 [0:v]scale=320:-1[320p]" \
-map "[1080p]" -c:v libwebp -q:v 85 output_1080.webp \
-map "[720p]" -c:v libwebp -q:v 85 output_720.webp \
-map "[480p]" -c:v libwebp -q:v 85 output_480.webp \
-map "[320p]" -c:v libwebp -q:v 85 output_320.webp

@SmilyOrg
Copy link
Owner Author

I also discovered yesterday that ffmpeg can scale and decode images also :)

ffmpeg -i input_image.cr2 -filter_complex \
"[0:v]scale=1080:-1[1080p]; \
 [0:v]scale=720:-1[720p]; \
 [0:v]scale=480:-1[480p]; \
 [0:v]scale=320:-1[320p]" \
-map "[1080p]" -c:v libwebp -q:v 85 output_1080.webp \
-map "[720p]" -c:v libwebp -q:v 85 output_720.webp \
-map "[480p]" -c:v libwebp -q:v 85 output_480.webp \
-map "[320p]" -c:v libwebp -q:v 85 output_320.webp

FFmpeg is actually already supported by default! :)

The default config is that it each file has 3 virtual thumbnails/variants backed by ffmpeg (256x256, 1280x1280, 4096x4096), which are generated on the fly if no other good source exists. You can also override this in your local config :)

photofield/defaults.yaml

Lines 320 to 342 in 31d4ede

#
# FFmpeg on-the-fly decoding
#
- type: ffmpeg
width: 256
height: 256
fit: INSIDE
cost:
time_per_original_megapixel: 120ms
- type: ffmpeg
width: 1280
height: 1280
fit: INSIDE
cost:
time_per_original_megapixel: 160ms
- type: ffmpeg
width: 4096
height: 4096
fit: INSIDE
cost:
time_per_original_megapixel: 180ms

In practice it works great across many popular file types (esp. for thumbnails of videos of course), but RAW support is a bit lacking. Some files work ok, others don't work at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

2 participants