gd

php add a picture onto another

两盒软妹~` 提交于 2019-11-28 11:57:27
问题 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 :) 回答1: You can try using GD's imagecopymerge function, which copies one image to another and supports alpha transparency. Something like this should

PHP/GD - Cropping and Resizing Images

纵饮孤独 提交于 2019-11-28 11:20:47
I've coded a function that crops an image to a given aspect ratio and finally then resizes it and outputs it as JPG: <?php function Image($image, $crop = null, $size = null) { $image = ImageCreateFromString(file_get_contents($image)); if (is_resource($image) === true) { $x = 0; $y = 0; $width = imagesx($image); $height = imagesy($image); /* CROP (Aspect Ratio) Section */ if (is_null($crop) === true) { $crop = array($width, $height); } else { $crop = array_filter(explode(':', $crop)); if (empty($crop) === true) { $crop = array($width, $height); } else { if ((empty($crop[0]) === true) || (is

How to check if an image has transparency using GD?

旧城冷巷雨未停 提交于 2019-11-28 10:58:45
How do I check if an image has transparent pixels with php's GD library? It doesn't look like you can detect transparency at a glance. The comments on the imagecolorat manual page suggest that the resulting integer when working with a true-color image can actually be shifted four times total, with the fourth being the alpha channel (the other three being red, green and blue). Therefore, given any pixel location at $x and $y , you can detect alpha using: $rgba = imagecolorat($im,$x,$y); $alpha = ($rgba & 0x7F000000) >> 24; $red = ($rgba & 0xFF0000) >> 16; $green = ($rgba & 0x00FF00) >> 8; $blue

How to get image resource size in bytes with PHP and GD?

偶尔善良 提交于 2019-11-28 10:17:23
I'm resizing images with php gd. The result is image resources that i want to upload to Amazon S3. It works great if i store the images on disk first but i would like to upload them directly from memory. That is possible if i just know the bytesize of the image. Is there some way of getting the size (in bytes) of an gd image resource? You could use PHP's memory i/o stream to save the image to and subsequently get the size in bytes. What you do is: $img = imagecreatetruecolor(100,100); // do your processing here // now save file to memory imagejpeg($img, 'php://memory/temp.jpeg'); $size =

Convert png file to ico with PHP

怎甘沉沦 提交于 2019-11-28 09:21:47
I would like to create a PHP script that convert a png file to an ico file. Is it possible to do it just with PHP ? How ? Thanks !!! The recently uploaded https://github.com/chrisbliss18/php-ico creates valid ICO files including multiple embedded resolutions from PNG files and other file formats using only PHP and the GD library. After some googling and light experimentation, it appears that an .ico file is basically a BMP with another file extension. I believe the ICO format supports more resolutions in one file, but a BMP seems to constitute a minimal ICO file. You should be able to generate

Image getting rotated automatically on upload

烂漫一生 提交于 2019-11-28 09:10:35
I'm trying to upload a base64 encoded image and save after decoding it. Image is getting uploaded and saved, and I can access it using a URL and everything..but the image gets rotated by 90 degrees anti-clockwise and I have no idea WHY!! The place where I get the encoded data is fine, as putting it in <img /> works fine! function saveImageData($base64Data) { $base64_decoded = base64_decode($base64Data); $im = imagecreatefromstring($base64_decoded); if ($im !== false) { $imagepath = '/public/uploads/' . time() . '.jpg'; imagejpeg($im, $imagepath); chmod($imagepath, 0755); imagedestroy($im); }

imageantialias call to undefined function error with GD installed

一笑奈何 提交于 2019-11-28 09:04:58
I need help with a php script. It is a CMS that has been implemented into a website. When trying to add a new product IMAGE or trying to edit current images, I am getting the following error: Fatal error: Call to undefined function imageantialias() in /home/mounts/home/m/mclh/web/admin/library/functions.php on line 233 This is my code for that area: if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg") { $destFile = substr_replace($destFile, 'jpg', -3); $dest = imagecreatetruecolor($w, $h); imageantialias($dest, TRUE); } elseif ($tmpDest['extension'] == "png") { $dest =

PHP/GD, how to copy a circle from one image to another?

扶醉桌前 提交于 2019-11-28 07:55:18
问题 Is there a reasonably straightforward way to copy a circular area from one image resource to another? Something like imagecopymerge except with circles or ovals etc? If possible, I want to avoid having to use pre-created image files (any oval shape should be possible), and if there's transparency colours involved they should naturally leave the rest of the image alone. Reason I'm asking, I have a few classes that allow to apply image operations inside a "selected area" of an image, which

PHP watermarking

♀尐吖头ヾ 提交于 2019-11-28 07:52:08
i am using this code to create watermark. $image = '1.jpg'; $overlay = 'stamp.png'; $opacity = "20"; if (!file_exists($image)) { die("Image does not exist."); } // Set offset from bottom-right corner $w_offset = 0; $h_offset = 100; $extension = strtolower(substr($image, strrpos($image, ".") + 1)); // Load image from file switch ($extension) { case 'jpg': $background = imagecreatefromjpeg($image); break; case 'jpeg': $background = imagecreatefromjpeg($image); break; case 'png': $background = imagecreatefrompng($image); break; case 'gif': $background = imagecreatefromgif($image); break; default:

How can I replace one color with another in a png 24 alpha transparent image with GD

﹥>﹥吖頭↗ 提交于 2019-11-28 06:38:13
问题 I have tried: $index = imagecolorresolve ( $im, 0,0,0 ); // get black imagecolorset($im, $index, 255, 0, 255); // SET NEW COLOR This seems to work with png 8 but not 24, and if I do it with 8 it turns out all weird because of the anti-aliasing. Here is the full test code I'm using. (this is just test code, so be gentle). function LoadPNG($imgname, $color = false) { $im = @imagecreatefrompng($imgname); imagealphablending($im, false); if($color) { $index = imagecolorresolve ( $im, 0,0,0 ); //