gd

Put PNG over a JPG in PHP [duplicate]

 ̄綄美尐妖づ 提交于 2019-11-28 05:59:05
This question already has an answer here: Transparent PNG over JPG in PHP 2 answers I want to do the following in PHP: I have two images, a jpg and a png. I want to resize the jpg to the same size as the png then put the png on top. The PNG has transparency so I would like to preserve that so the jpg shows underneath. If anyone could help that would be great! Thanks <? $png = imagecreatefrompng('./mark.png'); $jpeg = imagecreatefromjpeg('./image.jpg'); list($width, $height) = getimagesize('./image.jpg'); list($newwidth, $newheight) = getimagesize('./mark.png'); $out = imagecreatetruecolor(

Possible to add background color to transparent image using GD and PHP

本小妞迷上赌 提交于 2019-11-28 05:29:13
问题 I have the thumbnail creation class written with php language using GD. I want to know is when i upload the transparent image which is png or gif, can i be able to put background in that thumbnail image ? If that's possible, please kindly guide me how. Thanks. 回答1: Here's a working solution for PNG files: $filePath = ''; //full path to your png, including filename and extension $savePath = ''; //full path to saved png, including filename and extension $colorRgb = array('red' => 255, 'green' =

GD! Converting a png image to jpeg and making the alpha by default white and not black

余生颓废 提交于 2019-11-28 05:03:35
I tried something like this but it just makes the background of the image white, not necessarily the alpha of the image. I wanted to just upload everything as jpg's so if i could somehow "flatten" a png image with some transparently to default it to just be white so i can use it as a jpg instead. Appreciate any help. Thanks. $old = imagecreatefrompng($upload); $background = imagecolorallocate($old,255,255,255); imagefill($old, 0, 0, $background); imagealphablending($old, false); imagesavealpha($old, true); <?php $input_file = "test.png"; $output_file = "test.jpg"; $input = imagecreatefrompng(

Convert GD output to base64

南楼画角 提交于 2019-11-28 05:00:38
Well, my question is very simple, i just wanna convert the output of imagepng /imagejpg to base64, how i can do this ? the correctly way is with capturing output buffer ? thanks. imagejpeg / imagepng doesn't return any data, they write the image data directly to the output stream (or to a file). If you'd like to capture this data encoded as base64 the easiest method is to use PHPs Output Control Functions , and then use base64_encode on the $image_data . ob_start (); imagejpeg ($img); $image_data = ob_get_contents (); ob_end_clean (); $image_data_base64 = base64_encode ($image_data); The most

I can't use transparent background with imagecopymerge

*爱你&永不变心* 提交于 2019-11-28 04:27:04
问题 I am calling imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100); where $logo is a png file with transparent background. From some reason the background comes out white instead. What am I doing wrong? Thanks. 回答1: You need to use imagealphablending($dst_r, TRUE); to allow copying with retaining the transparent colors. Many more comments (...) in the manual suggest using imagecopy instead, because imagecopymerge was never intended to be used with transparency. If you use pct=100

Good way to identify similar images?

情到浓时终转凉″ 提交于 2019-11-28 03:09:44
I've developed a simple and fast algorithm in PHP to compare images for similarity. Its fast (~40 per second for 800x600 images) to hash and a unoptimised search algorithm can go through 3,000 images in 22 mins comparing each one against the others (3/sec). The basic overview is you get a image, rescale it to 8x8 and then convert those pixels for HSV. The Hue, Saturation and Value are then truncated to 4 bits and it becomes one big hex string. Comparing images basically walks along two strings, and then adds the differences it finds. If the total number is below 64 then its the same image.

Image upload security - reprocess with GD

ⅰ亾dé卋堺 提交于 2019-11-28 01:53:16
问题 I've heard that the best way to handle uploaded images is to "re-process" them using the GD library and save the processed image. see: PHP image upload security check list My question is how do this "re-processing" in GD ? What this means exactly? I don't know the GD library very well and I'm afraid I will mess it up... So if anyone who did this before could you give me an example for this? (I know, another other option is to use ImageMagick. For ImageMagick I found an answer here: Remove

How can I take a screenshot of a website with PHP and GD?

柔情痞子 提交于 2019-11-28 00:33:37
How can I create a screenshot of a website using PHP and the GD library. While you might be able to do something with imagegrabscreen or imagegrabwindow you'd only be able to use it on a Windows box, and even then it would be tricky. You'd have to open a browser window to the specified url (you could do that with exec ) and grab a screenshot using the aforementioned methods. Here's an example from the manual entry for imagegrabwindow : <?php $browser = new COM("InternetExplorer.Application"); $handle = $browser->HWND; $browser->Visible = true; $browser->Navigate("http://www.libgd.org"); /*

How can I merge 3 images into 1 image via PHP?

ⅰ亾dé卋堺 提交于 2019-11-27 22:31:15
I really cannot find a way to successfully do it.. I've searched google for this and it either has black shades around the images or all the images don't overlap. Could you please help? I am alright at PHP; I'd give myself a 2/5.. I would really appreciate if someone would be willing to help me out. I'm looking for a simple api that goes something like: $color=$_GET['color']; $face=$_GET['face']; $hat=$_GET['hat']; echo '<img src="avatar.php?color=$color&face=$face&hat=$hat">'; Thanks for any help in advance. I can understand php from my knowledge of other languages, too, so don't be afraid to

Programatically create image from web-page or a single DIV

我的梦境 提交于 2019-11-27 22:21:19
Is there any way to programatically create (client or server side (PHP)) a image from a specific DIV or a complete (web) page? I'm currently creating a web-site for free coupons and the idea is when the end-user clicks on the "Print" button, the app opens a new tab/window with all the selected coupons as a single image (JPG, PNG or etc..) in A4 format ready for printing. Each coupons has it's own data (Article name, price, description etc..) so I need it to be done programmaticaly over a coupon-template I designed. I do not ask you to write code for me, just to suggest a solution I could use