gd

How to preserve transparency when resizing PNG using Perl and GD

我的未来我决定 提交于 2019-11-30 05:41:11
问题 This is the code i'm using: !/usr/bin/perl use GD; sub resize { my ($inputfile, $width, $height, $outputfile) = @_; my $gdo = GD::Image->new($inputfile); ## Begin resize my $k_h = $height / $gdo->height; my $k_w = $width / $gdo->width; my $k = ($k_h < $k_w ? $k_h : $k_w); $height = int($gdo->height * $k); $width = int($gdo->width * $k); ## The tricky part my $image = GD::Image->new($width, $height, $gdo->trueColor); $image->transparent( $gdo->transparent() ); $image->copyResampled($gdo, 0, 0,

PHP & GD - transparent background being filled with nearby color

为君一笑 提交于 2019-11-30 04:57:48
问题 I know PHP+GD Transparency issues have been beat to death on this and many other sites, but I've followed all the recommendations and I can't seem to fix my issue. First, the explanation: I am trying to overlay one image on top of another one. They both have areas that are transparent. As a demo that I know should look a particular way, I am trying to overlay a checkmark on top of a blue arrow shape that I created. Here are the two images: Now to my code: I am using a library/API that I built

Image comparison with php + gd

一曲冷凌霜 提交于 2019-11-30 04:13:27
What's the best approach to comparing two images with php and the Graphic Draw (GD) Library ? This is the scenario: I have an image, and I want to find which image of a given set is the most similar to it. The most similar image is in fact the same image, not pixel perfect match but the same image. I've dramatised the difference between the two images with the number one on the example just to ease the understanding of what I meant. Even though it brought no consistent results, my approach was to reduce the images to 1px using the imagecopyresampled function and see how close the RGB values

Using GD in PHP, how can I make a transparent PNG watermark on PNG and GIF files ? (JPG files work fine)

心不动则不痛 提交于 2019-11-30 03:02:58
问题 I have an image (let's call it original image ) on which I want to watermark another image (let's call it logo ). The logo is a transparent PNG, whereas the original image can be png, jpg, or gif. I have the following code: function watermarkImage($originalFileContents, $originalWidth, $originalHeight) { $logoImage = imagecreatefrompng('logo.png'); imagealphablending($logoImage, true); $logoWidth = imagesx($logoImage); $logoHeight = imagesy($logoImage); $originalImage = imagecreatefromstring(

Resize images with transparency in php

梦想的初衷 提交于 2019-11-30 02:59:23
问题 I have looked all over for how to correctly manage alpha when I'm resizing a png. I've managed to get it to keep transparency, but only for pixels that are completely transparent. Here's my code: $src_image = imagecreatefrompng($file_dir.$this->file_name); $dst_image = imagecreatetruecolor($this->new_image_width, $this->new_image_height); imagealphablending($dst_image, true); imagesavealpha($dst_image, true); $black = imagecolorallocate($dst_image, 0, 0, 0); imagecolortransparent($dst_image,

Background image dark or light?

删除回忆录丶 提交于 2019-11-30 02:26:55
I'm doing a ODP->HTML conversion with PHP. I have problems with the following: Use the style:use-window-font-color property to specify whether or not the window foreground color should be as used as the foreground color for a light background color and white for a dark background color. (OpenDocument specification version 1.0, 15.4.4) If i have a background image, how do i check, if this image is light or dark? Do you have any ideas? Thanks in advance, Levu I thought this was quite an interesting problem to solve, so i hacked up a quick script to do it. following the other suggestions provided

How do You Resize a High Resolution Picture with PHP

旧城冷巷雨未停 提交于 2019-11-30 00:50:52
I'm processing images when the user uploads a pic but my problem is high rez pics. How do you detect when the user uploads one? I'm using the GD library for PHP. Setting the quality to 90 with the imagejpeg() method doesn't do anything to it but scales the dimension and then sets the ppi to 72. I want to be able to preserve the dimension and drop the ppi to 72 at the same time. Any advice would be greatly appreciated. There is no such thing as PPI as far as you need to be concerned. Also, DPI doesn't exist in digital. There are only pixels, and the dimensions (which are just a measurement of

Face detection in PHP

♀尐吖头ヾ 提交于 2019-11-30 00:32:55
Does anybody know of a good way to do face detection in PHP? I came across some code here that claims to do this, but I can't seem to get it to work properly. I'd like to make this work (even though it will be slow) and any help you can give me would be really appreciated. Here's the code from the link: <?php // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS

improve quality of PHP GD generated images

时光毁灭记忆、已成空白 提交于 2019-11-29 19:51:52
问题 i am going to start building a map generator in PHP using the GD library. i generated some images using the lib but they don't have a good quality. I just want to know that is there some way to improve the quality of the images. The generated image is: and the code i made is: <?php $canvas = imagecreate(800, 350); imagecolorallocate($canvas, 255, 255, 255); $pink = imagecolorallocate($canvas, 255, 105, 180); $white = imagecolorallocate($canvas, 255, 255, 255); $green = imagecolorallocate(

php add a picture onto another

女生的网名这么多〃 提交于 2019-11-29 18:24:15
I would like to change the color of an image with php. if I wanted to make it appear redder applicherei an image on a higher level across an image with a transparent red and more or less high can indicate how the original photo should be red. I can say gd php functions to create an image of a color (RGBA) and apply it to another image? thanks :) You can try using GD's imagecopymerge function, which copies one image to another and supports alpha transparency. Something like this should work: <?php $redimg = imagecreatetruecolor(100, 100); $image = imagecreatefrompng('image.png'); // sets