WordPress.org

Ready to get started?Download WordPress

Forums

User Photo
Transparent Background (4 posts)

  1. casperreiff
    Member
    Posted 2 years ago #

    When I upload a transparent PNG the background turns either white or black on the resized images

    http://wordpress.org/extend/plugins/user-photo/

  2. anttyc
    Member
    Posted 2 years ago #

    hey, the User Photo plugin doesn't handle transparency. If you want you can modify the code a little.

    here is what you need to do(User Photo ver. 0.9.5.1)
    code taken from: http://wordpress.org/support/topic/plugin-user-photo-transparent-png-support?replies=4

    1. open "user-photo.php"
    2. find line 899
      elseif ( $info[2] == IMAGETYPE_PNG ) {
      			if (!imagepng( $imageresized, $newFilename ) ) {
      				$error = __( "Thumbnail path invalid" );
      			}
      		}
    3. change it to
      elseif ( $info[2] == IMAGETYPE_PNG ) {
                      	@ imageantialias($imageresized,true);
          			@ imagealphablending($imageresized, false);
          			@ imagesavealpha($imageresized,true);
          			$transparent = imagecolorallocatealpha($imageresized, 255, 255, 255, 0);
          			for($x=0;$x<$image_new_width;$x++) {
          				for($y=0;$y<$image_new_height;$y++) {
          					@ imagesetpixel( $imageresized, $x, $y, $transparent );
         			 		}
          			}
          			@ imagecopyresampled( $imageresized, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $info[0], $info[1] );
         			if (!imagepng( $imageresized, $newFilename ) ) {
      				$error = __( "Thumbnail path invalid" );
      			}
      		}
    4. Upload your photo again
  3. casperreiff
    Member
    Posted 2 years ago #

    Thanks a lot, but it doesn't really work.
    Now it doesn't upload the photo at all.

    I'll just tell the client to make sure the image has a white background.

    Do you know if it supports transparent GIF from standard?

  4. andri86
    Member
    Posted 1 year ago #

    Thx. This code worked perfectly for me.
    I can upload PNG's whith transparent background.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags