• wpprogrammeurs.nl

    (@wordpressprogrammeursnl)


    Hi, I’m working on a form upload image resizer based on the new wp_get_image_editor, however when I try to resize PNG images down the resulting filesize gets LARGER <?> , the resize function works fine for other mime types (gif,jpg).

    Any ideas how to prevent the resized PNG’s from blowing up disproportionally ?? (going from a 960x800px 117 Kb -> 680x~560px -> 262 Kb )

    Here’s my code snippet :

    function resize_680($imfile = '') {
    	if (strlen($imfile) < 6) return false;
    	if (!is_writable($imfile)) return false;
    	list($width, $height, $type, $attr) = @getimagesize($imfile);
    	if ($width < 680) return false;
    	$newsize = wp_constrain_dimensions( $width, $height, 680, 680 );
    	$image = wp_get_image_editor( $imfile );
    	if ( ! is_wp_error( $image ) )
    		{
    		$image->resize( $newsize[0],$newsize[1], true );
    		$image->save( $imfile );
    		}
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The default image quality is 90, your source image probably has a much lower setting. Use $image->set_quality() to set it to something between 1 and 100.

    Thread Starter wpprogrammeurs.nl

    (@wordpressprogrammeursnl)

    @bcworkz I agree that set_quality() Would logically be the solution, however … I have tried that.
    Even with ridiculously low settings PNG images still swell up like a parched sponge thrown into a hottub.

    I’m having a similar problem. I’m uploading an optimize 8 bit png and all the generated sizes are 24 bit. For example, an original 720×720 png was 19K, however, the resized 220×220 was 29K, 330×330 51K, and 460×460 111K. Not only are the thumbnails significantly larger than the original but they are not optimized with lossless compression. I ran them through a compression utility which cut the size by about 40%! I’ve searched the internet for hours but have only found one reference to the problem and no solution.

    Moderator bcworkz

    (@bcworkz)

    Good catch noticing the 24 bit images! (wtf?) It appears the GD image editor is the only one that knows enough to convert 24bit to indexed. Not clear if it always does this, and if not, how to force it, nor the index size. So it may not help much.

    However, I do know how to force the GD editor to be used. Hook the ‘wp_image_editors’ filter. Return array( 'WP_Image_Editor_GD' ) . See if that helps any. There’s a chance you will just get an error, but worth a try. Good luck.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_get_image_editor makes PNG filesize larger instead of smaller’ is closed to new replies.