gd

How to clone a gd resource in PHP

烈酒焚心 提交于 2020-01-03 08:50:13
问题 I'm looking for cloning an image in PHP created with imagecreatetruecolor or some other image creation function.. As it was said in the comment, no you can't do a simple affection like : $copy = $original; This because ressources are reference and could not be copied like scalar values. Example : $a = imagecreatetruecolor(10,10); $b = $a; var_dump($a, $b); // resource(2, gd) // resource(2, gd) 回答1: This little function will clone an image resource while retaining the alpha channel

PHP+GD creating random black thumbnails

一曲冷凌霜 提交于 2020-01-02 09:57:32
问题 This function is creating some random black images like.. 10% of the time, is not much, but.. you know.. shouldnt be happening. class ImgResizer { private $originalFile = ''; public function __construct($originalFile = '') { $this -> originalFile = $originalFile; } public function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this -> originalFile); list($width, $height) = getimagesize($this -> originalFile);

Resizing and cropping image with GD while retaining aspect ratio

懵懂的女人 提交于 2020-01-02 04:30:27
问题 I'm currently coding an uploader script based on Uploadify. Right now I resize the given image and watermark one of the sizes. It all works well, but I need the script to resize the height and then crop the width so that the aspect ratio does not get messed up. This is my code so far: if ($fileExtension == "jpg" || $fileExtension == "jpeg" || $fileExtension == "png" || $fileExtension == "gif"){ // GD variables: list($width, $height, $type) = GetImageSize($uploadedFile['tmp_name']); // Image

kohana 3 uploading image without using any modules?

妖精的绣舞 提交于 2020-01-01 19:55:13
问题 does anybody have an example of uploading images in kohana 3 without using any modules eventually ? i used https://github.com/kohana/image/tree/3.1%2Fmaster but my error is: Fatal error: Uncaught Kohana_Exception [ 0 ]: Installed GD does not support images is there any easy and fast way to upload files in a kohana 3 based website? thanks! 回答1: Kohana API should help. Basic steps are: Create Validation object ( $array = Validation::factory($_FILES); ) Define rules ( $array->rule('file',

change color of image pixel by pixel

六眼飞鱼酱① 提交于 2020-01-01 19:36:16
问题 I an trying to change color of a png image so that transparent area still remain transparent and give rest of the image a color this is what i tried <?php $im = imagecreatefrompng('2.png'); $w = imagesx($im); $h = imagesy($im); $om = imagecreatetruecolor($w,$h); for ($x = 0; $x < $w; $x++) { for ($y = 0; $y < $h; $y++) { $rgb = imagecolorat($im, $x, $y); $colors = imagecolorsforindex($im, $rgb); $orgb = imagecolorallocate($om,$colors['alpha'],$colors['alpha'],$colors['alpha']); imagesetpixel(

Does the GD library use a lot of memory?

让人想犯罪 __ 提交于 2020-01-01 08:59:22
问题 I want to use GD library in my PHP script to generate a small thumbnail of a random big picture from external server. Every time the page is called, the GD library will regenerate a thumbnail and show it. Will this slow down the server or use up an unusual amount of memory? 回答1: GD use a lot of memory. It loads the image into memory entirely and uncompresses it, so you will need at least 32 bits per pixel. An image with the size 800 x 600 do then use up: 800 * 600 * 32 bits = 15.4 megabit = 2

php GD add padding to image

允我心安 提交于 2020-01-01 02:12:53
问题 I have found a few things on the web about PHP+GD regarding image manipulation, but none seem to give me what I am looking for. I have someone upload an image of any dimensions, the script I have written resizes the image to no more than 200px wide by 200px high while maintaining aspect ratio. So final image could be 150px by 200px for example. What I want to do is then manipulate the image further and add a matting around the image to pad it to 200px by 200px while not affecting the original

ImageMagick vs GD - which is faster, less resource intensive and produces better images?

时光总嘲笑我的痴心妄想 提交于 2019-12-31 11:04:08
问题 I need to choose between either ImageMagick or GD library for the following image manipulation tasks: resizing images into multiple sizes watermarking images As you can see I don't need anything fancy. I'm sure both these tools can achieve them, so if one has more extra features than the other, I don't really care about. My main concern is performance and quality. Which of these 2 tools consumes less resources, is faster and produces better quality images? P.S. I need to use it with their

PHP convert 24-bit colors to 4-bit

我只是一个虾纸丫 提交于 2019-12-31 06:08:05
问题 Background, I am converting images to ascii art. This works perfectly and even works with 24-bit color, converting the colors to the right rgb values. However, I now want to render the ascii art in 4-bit color palette rather than 24-bit. How do I convert 24-bit colors to 4-bit with PHP? More specifically, I have the standard IRC color pallet which I need to convert any given Hexidecimal or RGB value to. It is preferred that the colors match as best as possible when converted to the 4-bit

Colorize a PNG image using PHP GD

房东的猫 提交于 2019-12-31 05:09:42
问题 I've got a PNG image with a transparent background and a white circle. I'm trying to colorize the white circle into a specific color, but I'm having difficulty using this code: $src = imagecreatefrompng('circle.png'); $handle = imagecolorclosest($src, 255,255,255); imagecolorset($src,$handle,100,100,100); $new_image_name = "new_image.png"; imagepng($src,$new_image_name); imagedestroy($src) Any suggestions would be really helpful. Thank you in advance. 回答1: Your PNG image I assume has alpha