Piwigo
Piwigo copied to clipboard
New image formats support - WebP, AVIF, Heic
Hi,
There are opened different issues considering support of mentioned formats (WebP,Heif) by Piwigo. WebP and HEIC are for some time fully supported by major browsers and systems (well WebP is boycotted by apple - but this is their problem). Those formats are also supported for a long time by ImageMagick (and clones). So implementation (for someone knowing Piwigo code) should be quite straight forward.
Soon we should also have AVIF support for all browsers - but for other tools I guess it will take some time. Anyway - I think it's time to add those formats, and perhaps make it easier to add other new ones (without "switch" and "if's" - like it's now) in the future or Piwigo will fall behind the others.
Is this support even considered now?
Actually it seems that this should be extremely simple to do - but I'm not sure if it's the "proper" way. To accept and generate miniatures for webp images (it would be better to make all thumbnails and intermediate images webp also - even for jpeg) it's enough to modify 2 files:
/admin# grep -ri -A1 webp *
include/functions_upload.inc.php: if (IMAGETYPE_WEBP == $type)
include/functions_upload.inc.php- {
include/functions_upload.inc.php: $file_path.= 'webp';
include/functions_upload.inc.php- }
--
include/image.class.php: if (!in_array($extension, array('jpg', 'jpeg', 'png', 'gif', 'webp')))
include/image.class.php- {
There is also action.php/i.php in main directory - that perhaps also needs to be modified (not sure)
# grep -i -B1 webp *.php
action.php- case "gif": $ctype="image/gif"; break;
action.php: case "webp": $ctype="image/webp"; break;
--
i.php- case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break;
i.php: case ".webp": $ctype="image/webp"; break;
This works in my gallery.
Will this also generate webm for already existing images?
Will this also generate webm for already existing images?
Definitely not, it will also probably (just haven't checked) generate jpeg thumbnails for jpeg images, and webp only for webp images.
I see. I will try to develop script to convert all images and add full WEBP support.
I see. I will try to develop script to convert all images and add full WEBP support.
Hey any update on the code?
I would love this as well, especially for HEIC pics!
Any update on this in Piwigo 11? (I don't see any detailed changelog for 11).
First time checking out this software. Wondering if it still uploads heic and just doesn't render it or what support it's actually missing. Curious how it would affect me as a user.
There are two threads about this aberration at the forums which might give you some insight in the challenges they present
https://piwigo.org/forum/viewtopic.php?id=28440
https://piwigo.org/forum/viewtopic.php?id=29809
For me, what I would like to see is the option to import original HEIC files. Let me put it this way. Piwigo currently doesn't serve the original JPEG files when you are browsing a gallery. It serves resized JPEG files (while keeping the original JPEG intact and available as an optional download if the user really wants the original file). I would be happy with only the ability to import original HEIC files into my gallery with Piwigo generating resized JPEGs for various resolutions (as is currently done for JPEG originals). I have no interest at all in Piwigo serving HEIC files--just the ability to import and generate JPEGs. Hope this makes sense? Perhaps I should create a separate issue for this suggestion?
Piwigo mostly does not serve original files - but this depends on your skin/theme. In my case, when you enable full screen - it's an original file. But this is not a case here. JPEG is awfully old, and it's here just like painful GIF was (now mostly eradicated). There are new, better containers and codecs and there will be more. So this should be something that could be easily extended in the future. Now big sites (not all - but more, and more) are using webp - because it's supported for quite a long time in all browsers (so it's working for most of the users), and it allows to save traffic - just take a look at youtube (and NOT at the suffix - but the picture itself, because sometimes .jpeg contains webp images), all aliexpress/alibaba is on webp images. There is also HEIF/C container - that can have images encoded with HEVC/H265, video etc. - but for me, since it's proprietary, it's least important stuff. And we have AV1/AVIF in close proximity - where all the SOC already support it for future mobile usage.
With that long description I just want to point out, that this is bigger issue then just to add this picture type, or add that picture type - this should be more flexible in general.
I found in the forum that with the additional configuration it is possible to find additional format files, so with something like this
$conf['picture_ext'] = array('jpg','jpeg','png','gif', 'pef', 'orf'); $conf['file_ext'] = array_merge( $conf['picture_ext'], array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf') );
files with additional extensions are added to galleries (in my case *.ORF and *.PEF - two raw image formats) and the formats also added to picture_ext
are considered image formats.
Ideally all formats supported by the image converter tool (ImageMagick in my case) could be supported and be served with piwigo, as it usually resizes the files anyway. For this resizing, in my understanding, Piwigo takes the image path, modifies it with two letters indicating the resize size and gives the task to the converter to resize the file original_path to size whatever to derivative_path. From the file extension of said paths imagick deduces the desired output format - which is no problem for formats supported by imagick as output and browsers as input. It is, if e.g. imagick is not able to output those raw formats at all, and even if it could no browser could display it. Imagick can be forced to output to a certain format, even if it does not match the file extenison, but this is not really helpful either, because my browser did not display anything for a jpg file with a pef extension.
So what I tried was to append the extension .jpg to the derivative file path, if the current extension was not one of the originally supported image formats, and now imagick creates the required resized images. But it does not seem to serve the images on the first try, after reloading it works - I'm not sure wherever the derivative path is also created without the appended alternative jpg extension.
To get to the current state I:
- Changed the config as described
- Modified image.class.php to also contain other extensions for the image class not to die with "unsupported file extension":
if (!in_array($extension, array('jpg', 'jpeg', 'png', 'gif', 'orf', 'pef')))
- Added this if clause to modify the derivative path (i.php):
$extension = strtolower(get_extension($page['derivative_path']));
if (!in_array($extension, array('jpg', 'jpeg', 'png', 'gif')))
{
$page['derivative_path'].=".jpg";
}
Now it does serve my raw files (sometimes), but I'm also not sure what else gets broken by this modification.
as it's wide adoption a lot of images are now in .heic format. It would be a big plus to have support for this format. Thank you!
Just my 2¢: I would much rather prefer JPEG XL support (issue #1407) as a "first-class citizen", with its very interesting unique feature set (lossless forwards-and-backwards-compatible conversion from legacy JPEG, built-in responsive multi-sizes, etc. etc. at 60% smaller filesizes) and the fact that it is open-source, royalty-free and unencumbered by patents.
It might be helpful to know that there is already a PHP wrapper for JPEG XL handling:
https://github.com/joppuyo/jpeg-xl-encode
I have just installed piwigo for the first time and was very disappointed by the absence of the HEIC support. Almost all new images now in the HEIC format.
It is a shame as the iOS mobile app is really good, but it insists on converting to jpeg before uploading. I don't want to lose data through a conversion.
My $0.02. Considering that Apple iPhone sales have now surpassed Android phones, marketwise (at least in the US market), I think there's kind of no escaping the need to take the .HEIC format seriously...
My sense that it would be wise to add .heic, .webp, .avif and .jxl, just to be as compatible as possible, thereby removing reasons for new users to hesitate to migrate their photo collections to piwigo.
Amazing that this is even a discussion
I have added a post on this discussion https://piwigo.org/forum/viewtopic.php?pid=184432#p184432
If we have https://github.com/Piwigo/Piwigo/pull/1785, it's as easy as adding the new format to the extension. I tested this with webp and it worked. (e.g. the only change needed is in the admin/include/image.class.php as in the pull request)
It's all in https://github.com/Piwigo/Piwigo/pull/1785 now. This would support serving webp files. Maybe someone can test too?
I have just manually made the updates from #1785 to my install of 13.3.0 using the 'Modus' theme. The uploading and display of WebP images works fine. The only problem I am seeing is the other sizes for thumbnails are not being generated. Instead I just get the 'themes/default/icon/img_small.png' image stretched to the thumbnail size.
See bottom thumbnail here, which is my test WebP image:
If I click on that thumbnail then the full size WebP is displayed fine.
It is the only reason why I haven’t started using Piwigo. I use iPhone and Mac, all my photos and videos are HEIC and HEVC.
What is being forgotten is that not only is HEIF is not supported by any browser, but also that HEVC is a patent nightmare, which makes it a non-starter in my opinion. Other image formats such as WebP or AVIF are well supported with no patent problems, but they would still require some conversion from JPEG or HEIF.
In lieu of full support for HEIC, which is kind of a non-starter with the lack of browser support, would it be possible for Piwigo to allow them to be uploaded and just automatically create a JPEG version for display?
I have just manually made the updates from #1785 to my install of 13.3.0 using the 'Modus' theme. The uploading and display of WebP images works fine. The only problem I am seeing is the other sizes for thumbnails are not being generated. Instead I just get the 'themes/default/icon/img_small.png' image stretched to the thumbnail size.
If I click on that thumbnail then the full size WebP is displayed fine.
admin/include/image.class.php:
else if ($extension == 'webp') { $this->image = imagecreatefromwebp($source_filepath); }
In lieu of full support for HEIC, which is kind of a non-starter with the lack of browser support, would it be possible for Piwigo to allow them to be uploaded and just automatically create a JPEG version for display?
I agree and this is what we're going to do. HEIC has become the default file format created by iPhone Camera and now it seems common on Android too. Piwigo really needs to support it by default. Since we can't display an *.heic
file on a web browser, Piwigo will have to generate a *.jpg
file as "representative" (like we do for a PDF file)
For webP (which is less urgent in my opinion) we don't need the "representative" because it can be directly displayed on any web browser AND Piwigo (thanks to ImageMagick) can generated multiple-sizes as *.webp
files.
For Piwigo 14, we will be able to upload *.heic
files. Piwigo will generate a *.jpg
representative file and use it for displaying multiple sizes. The HEIC file will be kept as "original" file.
HEIC
was for me a highly important image format to support for Piwigo. It is indeed currently the default format used by iOS and Android.
Concerning WebP
and AVIF
: does any camera use these image format? or is "just" a format some advanced users decide to convert their JPEG files into? That make a big difference for Piwigo.