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

Webp full support #711

Merged
merged 7 commits into from
Jul 8, 2019
Merged

Webp full support #711

merged 7 commits into from
Jul 8, 2019

Conversation

lashus
Copy link
Contributor

@lashus lashus commented May 9, 2019

According to #501


private function loadWebp(string $data)
{
$tmpfile = tempnam(sys_get_temp_dir(), 'imaginewebp_');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that:

  1. The temporary directory should be configurable
  2. We should delete the temporary file once we've done reading it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's necessery. Why would we want to configure the temp directory for just loading the file?

Also if we want to delete the file we should probably do this somewhere else - we give the resource back and we cannot remove file that is currently opened as resources AFAIK. Perhaps on destructor of the class? To be honest - if it's in /tmp dir then filesystem will clear it eventually so it seemed like a "safe" choice :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen crappy hosting providers where the directory returned from sys_get_temp_dir() was not writable...

About deleting the file: PHP loads the file content in memory, so the file can be safely deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will fix that in next commit after we resolve the second issue.

return @imagecreatefromstring($data);
});

if($this->isWebp($data)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagecreatefromwebp has been introduced in PHP 5.4, but Imagine supports PHP 5.3.2. so what about

Suggested change
if($this->isWebp($data)) {
if(function_exists('imagecreatefromwebp') && $this->isWebp($data)) {

return @imagecreatefromstring($string);
});

if($this->isWebp($string)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagecreatefromwebp has been introduced in PHP 5.4, but Imagine supports PHP 5.3.2. so what about

Suggested change
if($this->isWebp($string)) {
if(function_exists('imagecreatefromwebp') && $this->isWebp($data)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you have to choose whether you want to support version that is 10 years old and unsupported since last 5 years or to use the image standard from 2010, early adopted by facebook & google in 2013 :) I'm all up for the latter but I can work on my fork so it's up to you.

Do you think that function check is good enough? Shouldn't we post some information that with the newer version of PHP this will be working at least?

(Sorry for the other comment, wrong account).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just do the function exists check. We can add a note to the changelog / release notes that webp support requires PHP 5.4+.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the new commit with your suggestion in it :)

@mlocati
Copy link
Collaborator

mlocati commented May 10, 2019

Tests are failing.
Also note the coding style issues.

@lashus
Copy link
Contributor Author

lashus commented May 10, 2019

Tests are failing.
Also note the coding style issues.

I've fixed code styling and tests. Do you want me to rebase as well? The Appveyor tests are failing but not because of my code :( There are a lot of issues with imagick from what I can tell.

@ausi
Copy link
Contributor

ausi commented Jul 4, 2019

I created an alternative pull request for this issue: #718

Instead of using a temp directory, it uses a data URI to load the WEBP image.

Maybe this would be a better solution? We often had issues with using sys_get_temp_dir() in the past.

*/
private function isWebp($data)
{
return 0 === strncmp(substr($data, 8, 7), 'WEBPVP8', 7);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same as substr($data, 8, 7) === 'WEBPVP8'?

@mlocati mlocati merged commit b3a25b4 into php-imagine:develop Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants