So I basically have this:
$img = imagecreatefrompng('assets/other/redcircle.png');
imagepng($img);
imagedestroy($img);
So the redcircle.png file has a transparency (with anti aliasing). But GD just turns all the transparency in black? Is there a way to get back the original transparency?
You have to tell GD to save the alpha using imagesavealpha: http://www.php.net/manual/en/function.imagesavealpha.php
Related
I'm currently building a site in app engine that uploads images to google cloud storage and to complete basic manipulations I'm using python's PIL
I've been having problems with the following image which another stackoverflow member has mentioned is a palette-based PNG with transparency, which I've been reading may be a bit buggy in PIL
My question is really a back to basics one: What is the best way to convert this to an RGB format with transparent pixels set to #FFF? I've been able to get it to work through a combined RGBA then RGB paste but that seems redundant
However, for a direct conversion I'm getting a bad transparency mask i.e. using the solution from PIL Convert PNG or GIF with Transparency to JPG without
Also if anybody has ideas why the image degrades to terrible quality after conversion, that's entirely a bonus for me!
A way to do this is to first convert the file to jpg -- seems like a problem with the png encoding (or something related to that)
Check out this link that I used and got smooth conversion from transparent PNG to GIF:
Convert RGBA PNG to RGB with PIL
The function you are looking for is pure_pil_alpha_to_color_v2.
I also used for my image conversion tool PySmile:
https://github.com/vietlq/PySmile/blob/master/pysmile.py
I am trying to script the creation of videos using ImageMagick to create some overlays which are then placed on top of a video.
If I try to use the image created by ImageMagick directly the transparency is drawn as opaque.
I have created a transparent PNG using ImageMagick draw commands. When loaded into GIMP and examined, the PNG has an alpha channel and each transparent pixel appears to have transparency: RGBA = 0,0,0,0
This image when then used as an overlay in ffmpeg just has an opaque black background in the video.
If I export the image again from GIMP then the file looks identical, but in the video just appears as a solid blue (the colour of the drawings in the overlay image).
I can fix this by taking the overlay image, loading it in GIMP and then selecting all and creating a new image from the clipboard and exporting that (using exactly the same settings as when I re-exported before without creating a new file) and it will then work exactly as desired, showing the non-transparent portions of the overlay and not showing transparent parts.
KEY QUESTION:
How can I either script the conversion that somehow occurs when creating a new file in GIMP, or (much better) not have it go wrong in the first place?
Here are the two files:
BROKEN:
WORKS:
What is the difference?
I suggest you prefix the output filename when using ImageMagick with PNG32: to force it to generate a 32-bit ber pixel image - i.e. 1 byte each for R, G, B and Alpha and hope that ffmpeg is happier with that.
convert input.png -draw ... PNG32:output.png
If you run identify -verbose (also in the ImageMagick suite) on your broken and your working images, you will see that the primary difference is that the working image has color-type=6 and bit-depth=8 whereas the broken image has color-type=3 (indexed) and bit-depth=4
I am trying to convert svg image to eps using Imagemagick. I am able to convert the image using Imagemagick, but the image size is too high when compared to the original image size and the content is not displayed correctly compared to the svg.
I was just wondering this too. However, it appears that Imagemagick might not be the best tool to do this.
Imagemagick is a "raster image processor," but SVG and EPS are vector formats. So using Imagemagick will cause those images to lose information as it has to convert from a vector format, to a raster format, and then back to vector. This probably explains why the contents of your image aren't correctly displayed.
Maybe consider using Inkscape to do this conversion using the following
# Works as of Version 0.92.4
inkscape ing.svg \
-E out.eps \
--export-ignore-filters \
--export-ps-level=3
where the -E flag is short for --export-eps to export EPS files.
Source:
http://imagemagick.org/Usage/formats/#vector
https://stackoverflow.com/a/30539923/6873133
Hi,
I have a transparent png format image.But SAP system does not support PNG format.So I want to convert it to either GIF or JPEG. I tried to convert it using Adobe Photoshop and some other tools but the resulted image loses its transparency. Can any body please tell me solution ??? Here is my image
yes you can convert png to either GIF or JPEG without losing transparency.......
this is done though the help of php lang...
<?php
$src = imagecreatefrompng("original_image.png");
$newImg = imagecreatetruecolor($nWidth, $nHeight);
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight,
$imgInfo[0], $imgInfo[1]);
imagejpeg($newImg,"jpec_test_1.JPG",100);
imagedestroy($src);
imagedestroy($newImg);
?>
You can't convert to JPEG as it does not support transparency. You should be able to conver to a GIF, just make sure to check the box next to transparency. However, the image you linked to actually does not appear to have transparency. Luckily, the image is a very simple gradient and you can easily reproduce this in Photoshop and then save it out as a GIF w/ transparency.
Even if I didn't quickly succeed to accomplish that with the Gimp, I've found a site which suits your needs. It is a online tool: you haven't to download anything, just upload your png image and then download the generated gif. Try it:
http://images.my-addr.com/converter_png_to_gif_online_freeware_tool.php
Hope it helps.
As noted by #Valjas, you JPEG doesn't support transparency. If you are converting just for reducing file size as JPEG has better compression, you might want to use https://tinypng.com/. It also has an API. I just used it for reducing file size of few PNGs.
BTW, I found this information while I was chasing the same problem ;)
I am doing image upload and resizing using the gd2 image library.
The image EXIF data is rotating my vertical pictures on resize. Is there a way to stop the image from rotating? or strip the exif data in php?
Barring learning the JPEG format and figuring out how to remove EXIF bit by bit...
You can use the GD library.
http://www.php.net/manual/en/function.imagecreatefromjpeg.php and http://www.php.net/manual/en/function.imagejpeg.php should do it.