gd

Better way to get map of all pixels of an image with GD

孤者浪人 提交于 2019-12-03 13:50:40
The following code uses the SimpleImage library I have a function that gets a pixel from an image: function getPixel($x, $y) { $colors = imagecolorsforindex($this->image, imagecolorat($this->image, $x, $y)); $n[0] = $colors['red']; $n[1] = $colors['green']; $n[2] = $colors['blue']; $str = "#"; for($x=0;$x < 3; $x++){ $n[$x] = intval($n[$x],10); if (is_nan($n[$x])) return "00"; $n[$x] = max(0, min($n[$x],255)); $bam = "0123456789ABCDEF"; $str .= $bam{($n[$x]-$n[$x]%16)/16} . $bam{$n[$x]%16}; } return $str; } To get every pixel in an image, I use this loop: $arr = []; for($y = 0;$y < $image-

How to create GD Image from base64 encoded jpeg?

五迷三道 提交于 2019-12-03 11:45:14
问题 I have an upload Api that as a response object delivers (along with other stuff inside a Json object) a base64 encoded jpeg image. I create the encoded image as so: $im; // gd image resource ob_start(); imagejpeg($im); $data = base64_encode(ob_get_clean()); The data then is put inside a form field using javascript and submitted. How can I create a GD resource from that again so that I actually can save that image as a file? Everything in PHP. 回答1: You can use imagecreatefromstring() function:

PHP/GD Gaussian Blur Effect

限于喜欢 提交于 2019-12-03 09:32:18
问题 I need to obfuscate a certain area of an image using PHP and GD, currently I'm using the following code: for ($x = $_GET['x1']; $x < $_GET['x2']; $x += $pixel) { for ($y = $_GET['y1']; $y < $_GET['y2']; $y += $pixel) { ImageFilledRectangle($image, $x, $y, $x + $pixel - 1, $y + $pixel - 1, ImageColorAt($image, $x, $y)); } } This basically replaces the selected area with squares of $pixel pixels. I want to accomplish some kind of blur (gaussian preferably) effect, I know I can use the

Resize an image and fill gaps of proportions with a color

廉价感情. 提交于 2019-12-03 09:00:47
I am uploading logos to my system, and they need to fix in a 60x60 pixel box. I have all the code to resize it proportionately, and that's not a problem. My 454x292px image becomes 60x38. The thing is, I need the picture to be 60x60, meaning I want to pad the top and bottom with white each (I can fill the rectangle with the color). The theory is I create a white rectangle, 60x60, then I copy the image and resize it to 60x38 and put it in my white rectangle, starting 11px from the top (which adds up to the 22px of total padding that I need. I would post my code but it's decently long, though I

Compiling PHP with GD and libjpeg support

☆樱花仙子☆ 提交于 2019-12-03 08:40:35
问题 I compile my own PHP, partly to learn more about how PHP is put together, and partly because I'm always finding I need modules that aren't available by default, and this way I have control over that. My problem is that I can't get JPEG support in PHP. Using CentOS 5.6. Here are my configuration options when compiling PHP 5.3.8: './configure' '--enable-fpm' '--enable-mbstring' '--with-mysql' '--with-mysqli' '--with-gd' '--with-curl' '--with-mcrypt' '--with-zlib' '--with-pear' '--with-gmp' '-

PHP Thumbnail Class

倾然丶 夕夏残阳落幕 提交于 2019-12-03 07:57:20
I am looking for a solid PHP thumbnail generating class. Does anyone know any good ones that are open-source? I could write one, but I really don't want to. The one thing I hate most about PHP is manipulating images with GD and Imagemagick. Does anyone have any suggestions? Use phpThumb() . Its a script that internally uses GD library and/or ImageMagick (whichever is available and whichever it thinks is best for the job) to perform basic image manipulation tasks, including thumbnail generation and square thumbnail generation. You can use it like this: <!-- best fit --> <img src="/phpThumb

Install GD library and freetype on Linux

烈酒焚心 提交于 2019-12-03 07:27:43
问题 I'm trying to use imagefttext. And I need to have GD library and/or freetype installed. I'm new to this kind of stuffs, How can I install GD library and freetype in Linux ? 回答1: Installing GD : For CentOS / RedHat / Fedora : sudo yum install php-gd For Debian/ubuntu : sudo apt-get install php5-gd Installing freetype : For CentOS / RedHat / Fedora : sudo yum install freetype* For Debian/ubuntu : sudo apt-get install freetype* Don't forget to restart apache after that (if you are using apache):

php imagecopyresized vs imagecopyresampled vs imagecopy pros/cons

雨燕双飞 提交于 2019-12-03 06:13:25
问题 These all seem to do the same thing. What are the pros/cons of each. imagecopyresized() vs imagecopyresampled() vs imagecopy(). I'm resizing a user submitted image. So I have an image shell created with '$newImage=imagecreatetruecolor(250, 250)'. And now I want to copy the orginal image into the '$newImage' 回答1: imagecopyresized will copy and scale and image. This uses a fairly primitive algorithm that tends to yield more pixelated results. imagecopyresampled will copy and scale and image, it

php GD add padding to image

∥☆過路亽.° 提交于 2019-12-03 05:48:33
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 image. For example: The code I have to get the image resized is here, I have tried a few things, but

Calculating Text Width with PHP GD

我是研究僧i 提交于 2019-12-03 05:09:22
问题 I'm simply trying to get the width of a dynamic line of text for addition to an image generated with GD PHP. I'm a little unsure how though. I know how to load a font using imageloadfont(), but can I use a .ttf file? I want to know the width of text using size 12 arial font. When I try to use my ttf file I get the error "Error reading font, invalid font header." If I need a .gdf file, where can I find a font size 12 gdf file? Here's my code: $newfont = imageloadfont("../fonts/arial.ttf");