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!
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.
Related
I need to manipulate images on the server-side via PHP. I use ImageMagick for that purpose, and there are a lot of great functions, but no documentation...
The issue is the next:
I have two images a png with a transparent background, and a jpg one;
I need to change the JPG image that has the same shape as the visible part of the PNG.
I don't want to crop the image, but to adjust to the PNG's visible part. Is that possible to do?
Example:
I have a default image that I want my users when they first create their profile to have, and I need to each one of them have a different background color but with the same base shape that will be in a png file, I can do this by creating for each background color create a png but I dont think it might be the best choice. How can I do this?
Use Imagick extension to work on your image. You can set a background color for your transparent png image by simply doing this
shell_exec("convert testimage.png -fill '#CCCCCC00' -opaque none image_wth_bgcolor.png");
This will give a slight gray(#CCCCCC) background to the the image.
See this link.
My suggestion is to create a png file for each colour (which seems to be the only way)
and use PHP to randomly pick one of the images.
Is it possible to make a transparent png image with php that has custom shape? For example, I've got a jpg image at server. Using php imagemagik or GD2 I would like to save it as transparent png and the transparency is custom shape. I hope it's clear. If it's not I will send an example.
Regards,
Dave
Umm it is possible to make it transparent, basically you can set a color as transparent, and the library will make each matching pixel transparent. I'm not sure what you mean by the shape though.
http://php.net/manual/en/function.imagecolortransparent.php
I am creating a script that can put a 24-bit transparent PNG image as a water mark on JPG/GIF/PNG images.
So, far i had success with JPEG and PNG.
But how can i achieve same with gif files? for GIF files, watermark do appear, but without transparency.
Please help.
Thanks,
Anjan
GIF images use indexed color palettes. In order to combine another image (your watermark) with the GIF image, whatever image library you're using (I'm guessing gd) is probably converting the PNG to an indexed-color format which is stripping out the alpha channel when it does so.
You probably need to find a way to convince it to convert the GIF image to a non-indexed color format first, then combine it with the watermark, and then write it back to an indexed-color GIF again.
I'm using PHP 5 GD Lib to do some graphic manipulations, and I can't find a way to get around the black background that shows up when you rotate an image or copy an image to another (larger) image.
Assuming that I am working with a JPEG file, which of course is not transparent, how can I rotate the image using GD Lib and end up with a white background / canvas, rather than black background?
This comment is from the PHP documentation and credit goes to "weareexit at yahoo dot co dot uk"
"If you want to place an image on a larger canvas you've previously created with imagecreatetruecolor(), but you don't want the default black background to surround it: use imagefill() AFTER imagecopyresampled()."