Jerre
Jerre

Reputation: 179

PHP image resizing and saving as png with transparent background

I'm working on a script for which I need to do the following:

User uploads an image (JPG, PNG, GIF). PHP resizes it, increases the canvas size, and saves the images as a PNG file on the server.

Now I found this tutorial to learn how to do that: http://www.webxpert.ro/andrei/2009/01/08/thumbnail-generation-with-php-tutorial/

However, this will create a PNG file with a white background. Is it possible to have PHP generate it with a transparent background?

Thanks!

Upvotes: 2

Views: 2985

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324840

The tutorial breaks it down into basic steps. Just find the step that puts a background colour in there, and put a transparent colour instead. You will need imagecolorallocatealpha and an alpha value of 127.

Upvotes: 1

Related Questions