• Resolved John Clause

    (@johnclause)


    Hi sewpafly,

    I love your plugin, and use it all the time. There is one little lack of functionality which I encountered and had to modify the code to make it work as expected.

    When one uses “Fit crop to thumbnail by adding border” option on original file with .jpg extension, a thumbnail preserves the extension, but .jpg does not support transparency and resulting thumbnail does not have transparent part as expected. Same problem will happen on any other image file type, which does not support transparency.

    As a workaround, I modified function pte_generate_filename as following:

    function pte_generate_filename( $file, $w, $h, $transparent=false ){
    	$options      = pte_get_options();
    	$info         = pathinfo( $file );
    	$ext          = $info['extension'];
    	$name         = wp_basename( $file, ".$ext" );
            $suffix       = "{$w}x{$h}";
            if($transparent) $ext = 'png';

    to replace the file extension with .png if the additional argument $transparent is true. I tried .gif extension too, but it does not keep transparency for some reason. Is .png the only choice for that purpose?

    Then I also added a line before the call to pte_generate_filename:

    $transparent = isset( $_GET['pte-fit-crop-color'] ) && abs($dst_w/$dst_h-$w/$h) > 0.01;
    		// Set the directory
    		$basename = pte_generate_filename( $original_file, $dst_w, $dst_h, $transparent );

    in order to set $transparency argument passed to pte_generate_filename. The file name extension will only be modified if the output thumbnail needs to have transparent part.

    Those two little changes solves my problem. Now the thumbnails, which require transparency, are saved with extension .png, regardless to what extension the source file has.

    Do you think you could add this or similar code addressing the problem in the next update, so that I do not have to keep doing those changes each time you update the plugin? I am sure some other folks has this problem too and they will appreciate the update as well.

    Thank you very much.

    https://wordpress.org/plugins/post-thumbnail-editor/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘thumbnail file extension when transparent color is enabled’ is closed to new replies.