gd

I have a base64 encoded png, how do I write the image to a file in PHP?

允我心安 提交于 2019-11-26 15:39:35
问题 What's the proper way in PHP to create an image file (PNG), when I have the base64 encoding? I've been playing around with: file_put_contents('/tmp/'. $_REQUEST['id'].'.png', $_REQUEST['data']); do I need to decode? should I be using the gd library? 回答1: My best guess is that you simply need to call base64_decode() on $_REQUEST['data'] before writing it to the file. That should be plenty enough :). 回答2: You need to use base64_decode(). AND. Sometimes it is not sufficient. Here is all code

PHP - Replace colour within image

ぃ、小莉子 提交于 2019-11-26 14:24:58
问题 I hope someone can help, I have made a script that masks images... however it is reliant on a colour to mask with ( 'green screen' style). The trouble is if the image that I am masking contains that colour it is ruined. What I am looking to do is prior to masking the image replace any occurance of my keying colour (0,0,255) with a similar colour such as 0,0,254. I have found a few solutions based around gif's or 256 colour PNG as they are indexed.. So my question is also will it be more

Convert tiff to jpg in php?

早过忘川 提交于 2019-11-26 14:16:19
问题 I have a server which holds TIFF images. Most clients can read and display TIFF images, so there's no problem. However, some clients can't handle this format but can handle JPG. I thought of using PHP's GD library to do a server side conversion for clients without TIFF reading abilities. But I noticed GD can't read TIFF files too. Imagick not working in windows, My idea was to create an imageFetcher.php which gets as a parameter the actual image the client wants. It checks the client's type

Crop image in PHP

巧了我就是萌 提交于 2019-11-26 14:07:24
The code below crops the image well, which is what i want, but for larger images, it wotn work as well. Is there any way of 'zooming out of the image' Idealy i would be able to have each image roughly the same size before cropping so that i would get good results each time Code is <?php $image = $_GET['src']; // the image to crop $dest_image = 'images/cropped_whatever.jpg'; // make sure the directory is writeable $img = imagecreatetruecolor('200','150'); $org_img = imagecreatefromjpeg($image); $ims = getimagesize($image); imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150); imagejpeg($img,$dest

Creating an image without storing it as a local file

别说谁变了你拦得住时间么 提交于 2019-11-26 13:46:24
问题 Here's my situation - I want to create a resized jpeg image from a user uploaded image, and then send it to S3 for storage, but am looking to avoid writing the resized jpeg to the disk and then reloading it for the S3 request. Is there a way to do this completely in memory, with the image data JPEG formatted, saved in a variable? 回答1: Most people using PHP choose either ImageMagick or Gd2 I've never used Imagemagick; the Gd2 method: <?php // assuming your uploaded file was 'userFileName' if (

How to add text to an image with PHP GD library

元气小坏坏 提交于 2019-11-26 13:08:53
问题 I have image creation code in image_creator. <?php header(\"Content-Type: image/jpeg\"); $im = ImageCreateFromGif(\"photo.gif\"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, \'verdana.ttf\', \"text to write\"); Imagejpeg($im, \'\', 100); ImageDestroy($im); ?> The file for image output is image.php and has below code <html> <head> </head> <body> <img src=\"http://localhost/image_creator.php\"/> </body> <

RGB to closest predefined color

天涯浪子 提交于 2019-11-26 12:17:29
问题 Edit: With the answer given I made this function function grabclosestcolor($r, $g, $b){ $colors = array(array(124,12,12),array(7,7,11),array(110,224,219),array(123,123,123),array(124,177,74),array(130,86,53),array(77,77,77),array(164,124,68),array(204,196,132),array(164,148,147),array(163,123,67),array(26,122,26), array(195,195,50),array(193,193,193),array(255,248,73),array(243,243,243)); $differencearray = array(); foreach ($colors as $value) { $difference = sqrt(pow($r-$value[0],2)+pow($g-

PHP function imagettftext() and unicode

喜欢而已 提交于 2019-11-26 11:11:56
问题 I\'m using the PHP function imagettftext() to convert text into a GIF image. The text I am converting has Unicode characters including Japanese. Everything works fine on my local machine (Ubuntu 7.10), but on my webhost server, the Japanese characters are mangled. What could be causing the difference? Everything should be encoded as UTF-8. Broken Image on webhost server: http://www.ibeni.net/flashcards/imagetest.php Copy of correct image from my local machine: http://www.ibeni.net/flashcards

Crop or mask an image into a circle

痞子三分冷 提交于 2019-11-26 10:53:52
问题 What is the best way to crop or mask an image into a circular shape, using either ImageMagick or GD libraries? (Note, solution exists on \"other\" Q&A sites, but not StackOverflow) 回答1: Here is one way with ImageMagick that will acomplish this without using a mask: convert -size 200x200 xc:none -fill walter.jpg -draw "circle 100,100 100,1" circle_thumb.png 回答2: For those who need to do this in pure PHP using Imagick , you will need to refer to this question : circularize an image with imagick

PHP GD Use one image to mask another image, including transparency

末鹿安然 提交于 2019-11-26 08:08:33
问题 I am trying to create a PHP script that takes an image: http://i.stack.imgur.com/eNvlM.png and then applies a PNG image: http://i.stack.imgur.com/iJr2I.png as a mask. The end result needs to maintain transparency: http://i.stack.imgur.com/u0l0I.png If at all possible I want to do this in GD, ImageMagick is not really an option right now. How would I go about this? phalacee\'s post (in \"PHP/GD, how to copy a circle from one image to another?\") seems to be along the right lines but I