mirror of
git://develop.git.wordpress.org/
synced 2025-02-24 16:43:06 +01:00
Fix setting default quality in WP_Image_Editor.
props markoheijnen. fixes #29856 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@29834 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
07a38ff81a
commit
1a7c4efa13
@ -114,7 +114,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
|
||||
$this->update_size( $size[0], $size[1] );
|
||||
$this->mime_type = $size['mime'];
|
||||
|
||||
return true;
|
||||
return $this->set_quality();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,10 +140,11 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
||||
}
|
||||
|
||||
$updated_size = $this->update_size();
|
||||
if ( is_wp_error( $updated_size ) )
|
||||
return $updated_size;
|
||||
if ( is_wp_error( $updated_size ) ) {
|
||||
return $updated_size;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $this->set_quality();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,10 +236,10 @@ abstract class WP_Image_Editor {
|
||||
* @param string $context Context of the filter.
|
||||
*/
|
||||
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
|
||||
}
|
||||
|
||||
if ( ! $this->set_quality( $quality ) ) {
|
||||
$this->quality = $this->default_quality;
|
||||
}
|
||||
if ( ! $this->set_quality( $quality ) ) {
|
||||
$this->quality = $this->default_quality;
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,8 +256,12 @@ abstract class WP_Image_Editor {
|
||||
* @return boolean|WP_Error True if set successfully; WP_Error on failure.
|
||||
*/
|
||||
public function set_quality( $quality = null ) {
|
||||
if ( null === $quality ) {
|
||||
$quality = $this->default_quality;
|
||||
}
|
||||
|
||||
// Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
|
||||
if ( $quality == 0 ) {
|
||||
if ( 0 === $quality ) {
|
||||
$quality = 1;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,9 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||
// Get an editor
|
||||
$editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
|
||||
// Check default value
|
||||
$this->assertEquals( 90, $editor->get_quality() );
|
||||
|
||||
// Ensure set_quality works
|
||||
$this->assertTrue( $editor->set_quality( 75 ) );
|
||||
$this->assertEquals( 75, $editor->get_quality() );
|
||||
@ -59,8 +62,8 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||
// Ensure the quality filter works
|
||||
$func = create_function( '', "return 100;");
|
||||
add_filter( 'wp_editor_set_quality', $func );
|
||||
$this->assertTrue( $editor->set_quality( 75 ) );
|
||||
$this->assertEquals( 75, $editor->get_quality() );
|
||||
$this->assertTrue( $editor->set_quality( 70 ) );
|
||||
$this->assertEquals( 70, $editor->get_quality() );
|
||||
|
||||
// Clean up
|
||||
remove_filter( 'wp_editor_set_quality', $func );
|
||||
|
@ -463,6 +463,9 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
|
||||
$file = DIR_TESTDATA . '/images/transparent.png';
|
||||
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
$this->assertNotInstanceOf( 'WP_Error', $editor );
|
||||
|
||||
$editor->load();
|
||||
$editor->resize( 5, 5 );
|
||||
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
|
||||
@ -483,6 +486,9 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
|
||||
$file = DIR_TESTDATA . '/images/transparent.png';
|
||||
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
$this->assertNotInstanceOf( 'WP_Error', $editor );
|
||||
|
||||
$editor->load();
|
||||
|
||||
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
|
||||
|
@ -463,6 +463,9 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
|
||||
$file = DIR_TESTDATA . '/images/transparent.png';
|
||||
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
$this->assertNotInstanceOf( 'WP_Error', $editor );
|
||||
|
||||
$editor->load();
|
||||
$editor->resize( 5, 5 );
|
||||
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
|
||||
@ -483,6 +486,9 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
|
||||
$file = DIR_TESTDATA . '/images/transparent.png';
|
||||
|
||||
$editor = wp_get_image_editor( $file );
|
||||
|
||||
$this->assertNotInstanceOf( 'WP_Error', $editor );
|
||||
|
||||
$editor->load();
|
||||
|
||||
$save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
|
||||
|
@ -224,6 +224,8 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
|
||||
// Save the image as each file extension, check the mime type
|
||||
$img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
$this->assertNotInstanceOf( 'WP_Error', $img );
|
||||
|
||||
$temp = get_temp_dir();
|
||||
foreach ( $mime_types as $ext => $mime_type ) {
|
||||
$file = wp_unique_filename( $temp, uniqid() . ".$ext" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user