-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Using webp as storage format for images #8358
Conversation
0c731c9
to
ae6c7cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks fine so far (except a small note), but as discussed in #8355 (comment), at least Ubuntu (18.04 and 20.04) doesn't support HEIC/HEIF yet, and 18.04 also doesn't support WEBP yet, but maybe we can ignore that one (but still has support for almost a year)? On the debian side we should be fine (debian 9/stretch which also doesn't support it yet is EOL in two days), and I didn't check the redhat based distros (I don't know these very well).
But I think Ubuntu 20.04 is the deal-breaker here, because that's still used on many servers and I don't know if we want to say we don't support that anymore. This is also the reason why the tests fail by the way.
So for me there are multiple possibilities now:
- We wait until we feel it's OK to cut off Ubuntu 20.04 (and everything else that might not support it yet)
- We find another solution how we can still support Ubuntu 20.04 (and the current solution of "just compile it yourself" isn't something I want to tell all the podmins still using 20.04).
- We add detection of what is supported and only allow HEIC/HEIF if it's supported and only use WEBP if it's supported (but I'm probably fine to drop 18.04 if this gets only merged to 0.8.x, so we maybe don't need to add detection for WEBP, but we maybe need to check if there are other distros which don't support it yet)
There is also something else to consider, because WEBP also isn't supported in all the browsers yet, because Safari needs a minimal macOS version to support WEBP (macOS 11 Big Sur or later). I'm not in the mac ecosystem enough to know how if most mac users have Big Sur or later already and it's fine, or if there are still many users with older macOS versions. And caniuse.com only shows how many % are using which Safari version, but they don't show percentages for macOS versions. On all my websites where I already use WEBP I still provide jpg/png fallbacks for the poor mac users, but that would require twice as much space on the pod and also would need support by all pods first (to show both versions), so it's not a solution here. So we need somebody familiar with the mac community to know if we can expect most mac users to use the latest macOS version or not.
Its a pitty with safaris support of webp. I admit I was not aware, that Safari (14) supports webp only since Big Sur. On the other hand.. Big Sur supports Hardware back since 2013 (see https://support.apple.com/en-us/HT211238 ), so this should not really bother a majority of users. On the server side, my pod Societas.online runs Ubuntu 20.02 and images just converts file to webp. I do not remember that I ever installed any special supporting libs. It even converts heic to webp, but "convert --version" do not show heic as a supported file format. Maybe the formats listed there are meant for writing? What do you think about adding a admin configuration setting for this feature? On the other hand, when the next diaspora major is released, it might be OK to cut of old habits? |
Yeah, I just want to know if we can expect most users to have already updated to Big Sur or later, or if many users still have an old version "because it still works and why should I update". Are older versions still supported by apple and get security updates, or would they need to update anyway? I just don't want a lot of people complaining that their images are broken (there are probably still some people using old browsers, but I don't care about the last person trying to use internet explorer, but I don't know if I should care about people using old macOS versions or if it's fine to ignore them).
As said, 20.04 supports WEBP, so that's expected.
That's more interesting, because the version in 20.04 doesn't list HEIC/HEIF as supported format, but the changelog says it's supported. Did you manually install
If 20.04 works with manually installing |
27633fd
to
e5c2738
Compare
@SuperTux88 |
Yes, I think we should only support WebP at the moment, that's a nice way to improve disk usage for podmin. I don't think phones are taking pictures in HEIF, are they? If not and only cameras are, then users need to first go through a computer anyway so they can convert them before uploading. |
Converting all uploaded images to the webp format.
981f92f
to
492ac74
Compare
The iPhone uses heif/heic images internally. If the user sends auch a photo (which's type the user don't know) to a Mac, the image will be send as a heic typed image. Only then the user makes contact tu auch a type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the PR, and I'm fine with only merging the webp part of it.
There is one last problem I found: this now breaks the image import. When importing a image archive, it stores the photos again, and before this PR it is used to generate all the thumbnails again (the archive only contains the original size). But with this PR the import would also convert everything to webp, which is a problem, because other pods expect the image to still keep the original filename and not suddenly change to a different extension/format. So all other pods would show broken images because they still link to the png/jpg variant of an image. So for the import to work we need a way to temporarily disable the conversion to webp from different formats for specific images. So png/jpg in the archive stay png/jpg, if the archive contains webp in the future they will be imported as webp (because new uploads will also be exported as webp in the archive).
@SuperTux88 |
@tclaus I think the import could contain both pngs and webp, so we have to be careful about that too. |
The problem with this is, that we don't really know when we are done with importing the photos, since the resizing of the images happens async (also for the import), so the import is finished before the all photos are resized. I was initially thinking of adding a flag to each photo we import, but then I realized we would need to add a column for that to the photos table so when reading the entity from the database again for the resize, it's still set correctly and I don't like to add a column only for the import (adding a flag to the user would have the same problem that it needs an additional column). My new idea is now to add an optional parameter to the
As already written in my review, that's not a problem, during the import pngs stay pngs, and webp stay webp ... we only need to disable (edit: we also need to disable line 29 ... so basically |
37fa8a7
to
5764b76
Compare
Hm - in photos.rb there will be a process started on after_commit. Line 51 in 5764b76
|
@tclaus I just noticed that the diff --git a/app/models/photo.rb b/app/models/photo.rb
index 0a77df62a..c776fe184 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -36,6 +36,8 @@ class Photo < ApplicationRecord
}, as: :status_message
end
+ attr_accessor :keep_original_format
+
mount_uploader :processed_image, ProcessedImage
mount_uploader :unprocessed_image, UnprocessedImage
diff --git a/app/services/import_service.rb b/app/services/import_service.rb
index cb6d02e3b..89e107452 100644
--- a/app/services/import_service.rb
+++ b/app/services/import_service.rb
@@ -74,6 +74,7 @@ class ImportService
def store_and_process_photo(photo, uploaded_file, random_string)
File.open(uploaded_file) do |file|
photo.random_string = random_string
+ photo.keep_original_format = true
photo.unprocessed_image.store! file
photo.update_remote_path
photo.save(touch: false)
diff --git a/app/uploaders/unprocessed_image.rb b/app/uploaders/unprocessed_image.rb
index 558202e3e..a653aa34f 100644
--- a/app/uploaders/unprocessed_image.rb
+++ b/app/uploaders/unprocessed_image.rb
@@ -31,7 +31,7 @@ class UnprocessedImage < CarrierWave::Uploader::Base
def needs_converting?
extname = File.extname(@filename)
- %w[.webp .gif].exclude?(extname)
+ %w[.webp .gif].exclude?(extname) && !model.keep_original_format
end
process :basic_process |
Did you notice that the image is not processed directly but in a job queue? So I think by starting the job it should be distinguished between convert format and not. The job just gets the photo ID. |
As said, the job only does the resize into different sizes, it doesn't change the format, it keeps the format that's already used in the |
5764b76
to
1197304
Compare
app/uploaders/unprocessed_image.rb
Outdated
def initialize(*) | ||
@convert_format = true | ||
super | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a leftover from the old commit
|
||
|
||
module Workers | ||
class ProcessImportedPhoto < Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this worker isn't needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought this was removed..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now 🍪
ac4d8bc
to
f995e6a
Compare
Supporting heic images to be uploaded.
Posts now support the upload of png, jpg, heic and webp image formats.
Files are converted to the web optimized webp format after upload
Issue: #8355