gd

How to loop through all the pixels of an image?

旧街凉风 提交于 2019-12-09 17:48:51
问题 I want to loop through all the pixels of an image, find the rgba value of that pixel, and do something with those pixels. Example Say I have an image that's 100x100 pixels. I want to find the value of each one of those pixels with the function I already made: function getPixel($image, $x, $y) { $colors = imagecolorsforindex($image, imagecolorat($image, $x, $y)); $inrgba = 'rgba(' . $colors['red'] . ',' . $colors['green'] . ',' . $colors['blue'] . ',' . $colors['alpha'] . ')'; return $inrgba;

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

╄→尐↘猪︶ㄣ 提交于 2019-12-09 11:33:09
问题 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}; }

Image watermarking in php

╄→尐↘猪︶ㄣ 提交于 2019-12-09 07:17:56
问题 I want to watermark an image and save it. here is the code i am using for it. Here it is outputting the image and is storing that output to the file. I want to save it without outputting it. // Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng('stamp.png'); $im = imagecreatefromjpeg('proverbs.jpeg'); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp);

Trying to save base64 image using imagecreatefromstring and it is completely black

牧云@^-^@ 提交于 2019-12-09 06:00:05
问题 I am trying to take a Base64 encoded image from the database and save it to a file. For whatever reason, when I try using imagecreatefromstring & imagepng the image is completely black. I have tried many different approaches, but I still end up with a black box. Below is my best attempt to get it to work. Any ideas? Thank you so much in advance! $thefile = base64_decode($strImage); $img = imagecreatefromstring($thefile); if($img !== false) { header('Content-Type: image/png'); imagepng($img);

Convert JPEG to a Progressive JPEG in PHP

若如初见. 提交于 2019-12-09 01:45:41
问题 I'm trying to re-save an already created JPEG as a progressive jpg. Basically, on the front end I have some JS that crops an image, and outputs a base64 image JPEG. Once it is passed to the PHP script, I create it as a regular JPEG file, like so: $largeTEMP = explode(',', $_POST['large']); $large = base64_decode($largeTEMP[1]); file_put_contents('../../images/shows/'.$dirName.'/large.jpg', $large); I'm wanting this jpg image to be progressive, so I was looking around and found the PHP

Optimize uploaded images with php (jpeg)

十年热恋 提交于 2019-12-08 22:46:06
问题 When running Page Speed in Google Chrome it suggests to optimize/compress the images. These images are mostly uploaded by users, so I would need to optimize them during uploading. What I find about optimizing jpeg images with php is something like using the following GD functions: getimagesize() imagecreatefromjpeg() imagejpeg() Since I am resizing the images after upload I'm already pulling the image through these functions and in addition I use imagecopyresampled() after imagecreatefromjpeg

PHP gdLib 8-Bit PNG with alpha

元气小坏坏 提交于 2019-12-08 17:07:37
问题 how is it possible to save my image, created with gd, as an png-8? it saves as gif with transparent channel well - but I want to use png-8. Best Regards, Beerweasle 回答1: Using imagesavealpha() and a transparent bg color should do the trick... Based on dfilkovi's code: <?php // Create a new true color image $im = new imagecreatetruecolor(100, 100); // Fill with alpha background $alphabg = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefill($im, 0, 0, $alphabg); // Convert to palette-based

Masking one image against another using PHP GD

时间秒杀一切 提交于 2019-12-08 13:48:14
问题 Please see this question: PHP GD Use one image to mask another image, including transparency - The rules around here say for users to create new questions rather than revisit old ones and ask for support I've been working with this script to enable transparent masking - the (possible) difference being that the source image has transparency, but it seems like the code below only works if the input PNGs have no transparency. Can someone have a look and see if I'm doing anything wrong? What I'm

Adding of Image Layer Fails (GD) PHP

五迷三道 提交于 2019-12-08 13:35:17
问题 I've installed the GD Library on my Apache just now, and it seems that my script below doesn't work. I'm trying to add a layer "play.png" to a youtube video thumbnail (http://img.youtube.com/vi/VIDEOID/default.jpg) I've tried it with many different videoID's but the image doesn't load. There is a message that the graphic couldn't be opened because it contains errors. I'm opening the file with postimage.php?v=7yV_JtFnIwo http://img.youtube.com/vi/7yV_JtFnIwo/default.jpg opens correctly too...

can I have multiline text with GD and PHP?

五迷三道 提交于 2019-12-08 13:30:57
问题 I'm trying to output multiline text with GD+PHP but can't get it working. my php knowledge is really basic. here's the code, any idea on how to output 2 or 3 lines of text? $theText = (isset($_GET['caption']))? stripslashes($_GET['caption']) :''; imagettftext($baseImage, $textSize, $textAngle, $textXposition, $textYposition, $textColor, $fontName, $theText); 回答1: imagettftext($baseImage, $textSize, $textAngle, $textXposition, $textYposition, $textColor, $fontName, $theText); imagettftext(