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

PHP 8.1 with AVIF Support in GD extension #834

Closed
robots4life opened this issue Aug 26, 2021 · 6 comments
Closed

PHP 8.1 with AVIF Support in GD extension #834

robots4life opened this issue Aug 26, 2021 · 6 comments
Labels

Comments

@robots4life
Copy link

The GD extension in PHP 8.1 and later supports the AVIF image format, making it possible to convert images from and to AVIF.
For this to work the GD extension must be compiled with AVIF support.
It depends on libavif package, which may not be available in default repositories of older operating system versions.

https://php.watch/versions/8.1/gd-avif#compile

Could you kindly compile PHP 8.1 with AVIF support ?

@llaville
Copy link
Contributor

It's not yet possible due to a bug (segmentation fault), see https://bugs.php.net/bug.php?id=81217

Even my alternative, what use a recent version (8.1.0beta3) is not able to add gd with AVIF support.

@robots4life
Copy link
Author

robots4life commented Aug 27, 2021

@llaville Thx for pointing this out. Hopefully at some point this will work.

While this is currently not possible perhaps you have an idea how to tackle this.
On the PHP side I want to verify an AVIF file is really an AVIF file and not just an JPEG with an AVIF extension, usually this is done with FILEINFO_MIME_TYPE. https://www.php.net/manual/en/function.mime-content-type.php also does not work.

$finfo          = finfo_open( FILEINFO_MIME_TYPE );
$file_mime_type = finfo_file( $finfo, $value['file_path_avif'] );
finfo_close( $finfo );
dump( $file_mime_type );

This naturally returns application/octet-stream as mime type and is wrong.
Is there any other way, with current PHP 8 or 8.1 methods, to verify a file is really an AVIF file ?

Solution - I had to get the file contents as a string and then 8 characters starting at 4.

// https://www.php.net/manual/en/function.file-get-contents.php

$avif_file_contents = file_get_contents( $value['file_path_avif'], false, null, 4, 8 );
dump( $avif_file_contents );

if ( 'ftypavif' === $avif_file_contents ) {

	echo $avif_file_contents;
	echo 'This is an AVIF file.';

}

🤞 this will not give any false results..

@llaville
Copy link
Contributor

@robots4life Good news. Project docker-php-extension-installer since today release 1.2.65 add support to enable AVIF for GD on PHP 8.1

And I've already mentioned it, my alternative which is almost compatible to https://github.com/devilbox/docker-php-fpm (see my current ROADMAP to learn more about compatibility between two solutions) used the docker-php-extension-installerproject to add extension in mods image

@robots4life
Copy link
Author

@llaville Good work and thank you for the update on this.

For local development this is good, going live, many hosts have not implemented this and imo this will still take a while. For working with JPEG files and converting them to AVIF I can observe a trend where some basic PHP hosts have Node on the console, with this I pass the files to the Node process, convert them there with Sharp and pass them back to the location where PHP can serve them. This works locally and live for the hosts in question.

However, it would also be cool to know if the docker-php-extension-installer project can/could be used to enable AVIF for GD on PHP 8.1 in Devilbox.

@llaville
Copy link
Contributor

llaville commented Oct 2, 2021

However, it would also be cool to know if the docker-php-extension-installer project can/could be used to enable AVIF for GD on PHP 8.1 in Devilbox.

/cc @cytopia

This was referenced Jan 26, 2022
@cytopia
Copy link
Owner

cytopia commented Jan 28, 2022

@cytopia cytopia closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants