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

1.x Fix a bug when Gif images were converted to WebP images #57

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function picture_responsive( $args = [] ) {

$args = wp_parse_args( $args, $default_args );

$to_webp = ! empty( $this->size['webp'] );
$to_webp = $this->is_webp();
$mime_type = false;
$html = '';

Expand Down Expand Up @@ -995,6 +995,7 @@ public function is_webp() {
return isset( $this->size['webp'] )
&& $this->size['webp']
&& ! $this->is_svg()
&& ! $this->is_gif()
&& ! $this->is_pdf();
}

Expand Down
29 changes: 29 additions & 0 deletions tests/test-webp.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,33 @@ public function test_webp_not_generated_in_image_metadata() {

$this->assertEquals( 'image/jpeg', $metadata['sizes']['large']['mime-type'] );
}

public function test_timmy_ignores_gif_when_using_webp() {
$attachment = $this->create_image( [ 'file' => 'logo-small.gif' ] );

$image = Timmy::get_image( $attachment, 'webp' );

$result = $image->picture_responsive();
$expected = sprintf(
'<source srcset="%1$s/logo-small-100x0-c-default.gif">
<img src="http://example.org/wp-content/uploads/2023/04/logo-small-100x0-c-default.gif" width="100" height="50" alt="" loading="lazy">',
$this->get_upload_url()
);

$this->assertSame( $expected, $result );
}

public function test_timmy_ignores_svg_when_using_webp() {
$attachment = $this->create_image( [ 'file' => 'sveegee.svg' ] );

$image = Timmy::get_image( $attachment, 'webp' );

$result = $image->picture_responsive();
$expected = sprintf(
'<img src="%1$s/sveegee.svg" width="1400" height="1400" alt="" loading="lazy">',
$this->get_upload_url()
);

$this->assertSame( $expected, $result );
}
}