gd

Finding spot on an image - mathematical way?

◇◆丶佛笑我妖孽 提交于 2019-12-04 20:25:11
I need to find a predefined area on an image and replace it with the other image (by just embedding the latter). The predefined spot would be a variable size rectangle area filled with solid background of the previously agreed colour. Any advise on how do I achieve this? I guess I can find a first pixel of the specified colour by doing a loop and going through the image row by row, pixel by pixel, but I feel like that's not the most efficient solution. Since the spot is supposed to be rather big, I also thought about going across the picture (please see the attachment below). So I need help in

Add whitespace to image and save file to server

南楼画角 提交于 2019-12-04 19:35:45
I have a script that generates some HTML for newsletters. I'm floating an image using "align=left" and wrapping text around it. I use an inline CSS style, in this case margin-right, to give the image some breathing room. Outlook ignores this. Outlook also ignores padding - I even tried a 10px border-right, it ignored that, too. I can't change the layout and put the image in a table. I am thinking of using GD to manipulate the image, adding 8px of whitespace to the right side of it. The catch is, since this is a newsletter going out to thousands of people, is that I then need to save the

change color of image pixel by pixel

浪子不回头ぞ 提交于 2019-12-04 19:30:28
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($om,$x,$y,$orgb); } } header('Content-Type: image/png'); imagepng($om); imagedestroy($om); imagedestroy

Image Resizing in (PHP/GD)

馋奶兔 提交于 2019-12-04 19:19:33
I'm looking for help/suggestions in finding the most efficient way to resize an image to be as small as possible using PHP/GD while preserving the aspect ratio of the original image but ensuring the the resized image is bigger than a defined minimum width & height. For example, the resized image must have a width >= 400 and a height >= 300 but should be as close to those dimensions as possible while maintaining the original aspect ratio. Such that a "landscape" image would have an ideal height of 300 or slightly larger with a width >= 400 and a "portrait" image would have an ideal width of 400

PHP GD resizing transparent image giving black border

╄→гoц情女王★ 提交于 2019-12-04 18:28:57
问题 I am trying to downsize some transparents images in PHP with GD, and whenever I do, there is a weird black-ish border that is added around it. Before After Code <?php $image = imagecreatefromstring(file_get_contents('logo.png')); $width = imagesx($image); $height = imagesy($image); $newWidth = $width - 1; $newHeight = $height - 1; $output = imagecreatetruecolor($newWidth, $newHeight); imagecolortransparent($output, imagecolorallocatealpha($output, 0, 0, 0, 127)); imagealphablending($output,

Fetching a file on a server, resizing with PHP GD2, security considerations

白昼怎懂夜的黑 提交于 2019-12-04 18:02:45
What are the security considerations when a server fetches a file from an untrusted domain? What are the security considerations when resizing an image that you don't trust with PHPs GD2 library? The file will be stored on the server machine, and will be offered for download. I know I can't trust the MIME-Type header. Is there anything else I should be aware of? I have a webservice that looks like this: input An http-URL (or a String that is expected to be a URL) output A meta description of the file, or an error if there was one. The meta description has one of two forms: It's an image + a

PHP GD Jpeg with a target filesize

不羁岁月 提交于 2019-12-04 17:28:22
I'd like to feed PHP/GD an image resource and a target file size and have it output a JPEG file of that target size. Say, I have a 500KB PNG image that needs to be 100KB. Example. function target_image_filesize($im,$target_size){ //create gd image //return a new image resource of specified size } I know I've seen a function for this floating around, and it's not something I'm looking to re-invent if possible. The trick will be in specifying proper JPEG quality. But this parameter is never defined, here you can read that: In fact, quality scales aren't even standardized across JPEG programs.

Resize an image and fill gaps of proportions with a color

南楼画角 提交于 2019-12-04 15:52:24
问题 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

PHP GD - Align text center-horizontally and decrease font size to keep it inside the image

北战南征 提交于 2019-12-04 13:53:21
问题 Hope you are doing great. I’m still a newbie with php so after making some reading and while checking some posts here I was able to put some text over an image with the imagecreatefrompng() function using the PHP GD, users will come to a form and they will be able to enter their name and the name will be written over the image , unfortunately I have been unable to align the text center horizontally, I tried all ways possible (my ways obviously and must be wrong) with imagettfbbox but I failed

PHP sharpness convolution martix

谁都会走 提交于 2019-12-04 13:02:14
I'm using a convolution matrix for sharpness in PHP GD and I want to change the sharpness "level" . Where would I make changes to this if I want to make it more or less sharp ? $image = imagecreatefromjpeg('pic.jpg'); $matrix = array( array(0, -1, 0), array(-1, 5, -1), array(0, -1, 0) ); imageconvolution($image, $matrix, 1, 0.001); header("Content-type: image/jpeg"); imagejpeg($image); try looking on http://www.gamedev.net/reference/programming/features/imageproc/page2.asp There are lots of examples on the web, but as a rule of thumb you may try these params first in GIMP or PS or any other