Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GD Image Manipulation —

Featured Replies

Hi all,

I'm doing a simple overlay of a transparent PNG onto a solid background. 'imagecopyresized' does the trick transparency-wise, but obviously the overlaid image is jagged. When using 'imagecopyresampled', everything is smooth but images with transparent backgrounds get a weird noise where the transparency should be. Any ideas? Here comes the code and an example:

 

// Preview image functions

			// 6a. Generate the preview image background (590x520)
			$tshirtbackgroundimage = imagecreatefrompng("./shirttemplate.png");
			$shirtimagepreview = imagecreatetruecolor(590,520);
				imagealphablending($shirtimagepreview, false);
				imagesavealpha($shirtimagepreview,true);
				$transparent = imagecolorallocatealpha($shirtimagepreview, 255, 255, 255, 127);
				imagefilledrectangle($shirtimagepreview, 0, 0, 590, 520, $transparent);
					imagecopyresampled($shirtimagepreview, $tshirtbackgroundimage, 0, 0, 0, 0, 590, 520, 590, 520);
					imagealphablending($shirtimagepreview, true);



			//6b. Resize the original image
			$newimageheightpreview = 280 * ($uploadedfileheight / $uploadedfilewidth);
			$shirtimagepreviewfront = imagecreatetruecolor(280,$newimageheightpreview);

				imagealphablending($shirtimagepreviewfront, false);
				imagesavealpha($shirtimagepreviewfront,true);
				$transparent = imagecolorallocatealpha($shirtimagepreviewfront, 255, 255, 255, 127);
				imagefilledrectangle($shirtimagepreviewfront, 0, 0, 280, $newimageheightpreview, $transparent);
					imagecopyresampled($shirtimagepreviewfront, $uploadedimage, 0, 0, 0, 0, 280, $newimageheightpreview, $uploadedfilewidth, $uploadedfileheight);


			// 6c. copy one to the other
			imagecopy($shirtimagepreview,$shirtimagepreviewfront,155,105,0,0,280,$newimageheightpreview);

 

 

Also, it's too late to back out of GD for this project, but does anyone have any heartfelt recommendations for another image library to use with php?

Thanks!

post-15983-125840373226_thumb.txt

  • Author

ImageSaveAlpha:

 

Thanks for the suggestion—am I using imagesavealpha in completely the wrong way?! I've tried every combination of true and false for imagesavealpha and imagealphablending, but anything other than what I have causes one or both of the images' backgrounds to be drawn black. The only thing I can think is that I have a complete misconception about how one of the functions works, as everything looks as it should to me! Cheers.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.