gd

Why GD doesn't release memory upon imagedestroy()?

☆樱花仙子☆ 提交于 2019-12-23 17:23:09
问题 I need a PHP CLI script to do various image transformations via GD functions. The images are quite big so I need to squeeze as much memory as possible. However, imagedestroy() seems not to release memory when asked. Consider following demo script 'test.php': #!/usr/bin/php5 <?php $memory = [0=> memoryCheck()]; $res1 = imagecreatetruecolor(8192, 4096); memoryReport('Res1 created'); $res2 = imagecreatetruecolor(8192, 4096); memoryReport('Res2 created'); imagedestroy($res1); memoryReport('Res1

PHP - Rotate image with GD gives black borders

断了今生、忘了曾经 提交于 2019-12-23 15:23:48
问题 I am trying to rotate and save an image. The rotation is based on the EXIF data. I have tried the following, which all give a black border around it: Where the original looks like this: $orientation = array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[@exif_read_data($imagePath)['Orientation'] ?: 0]; $source = imagecreatefromjpeg($imagePath); $resource = imagerotate($source, $orientation, 0); imagejpeg($resource, $image, 100); I have also tried adding imagealphablending($resource, true); and

Alternative for PHP GD library in python

你离开我真会死。 提交于 2019-12-23 12:57:45
问题 I was searching searching for a pure python module which has functionality equalent to PHP GD library. I need to write text on a image file. I know PHP GD library can do that. Does any one know about such module in python too. 回答1: Yes: the Python Imaging Library or PIL. It's used by most Python apps which need to do image processing. 回答2: Since you're looking for "pure Python modules", PIL might not be OK. Alternatives to PIL: mahotas. It's not pure, but it only depends on numpy, which is

No orientation in exif data - PHP image upload

☆樱花仙子☆ 提交于 2019-12-23 12:46:05
问题 been trying to detect the image orientation of uploaded images from iPhones and then adjust their orientation from that. I am trying to fix the issue where images taken in potrait, are uploaded with a -90 degree rotate. I tried numerous switch statements which were not working, so decided to return the exif data in my JSON return. The issue i see is that their is no orientation in the exif data. I am doing so: $imagefile = $fileToUpload["tmp_name"]; $destinationImage = imagecreatefromstring

How to handle “gd-png: fatal libpng error: Read Error: truncated data” in php 7

天涯浪子 提交于 2019-12-23 10:09:43
问题 I use php 7.0.22 (Ubuntu 17.04) When some user upload PNG with truncated data and i use: $a = imagecreatefrompng($path); then I get crash with: Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in ###.php on line ### I try to use try{...code...}catch(\Throwable $e){...echo...}. and $a = @imagecreatefrompng($path); But script just dies with same error message. Use of imagecreatefromstring(file_get_contents($path)) has same result. My validation of PNG: I

Merging multiple overlapping transparent png images with php

故事扮演 提交于 2019-12-23 05:20:05
问题 I have a custom bicycle configurator that layers transparent png files with css. http://www.gallantbicycles.com/build/no1/ I need to add the ability to combine them into one file dynamically so the user can download an image or share it. This is where I'm at right now, but it results in a black background and only the front most image is seen in the result: $width = 720; $height = 500; $layers = array(); $layers[] = imagecreatefrompng("pathtomyimage/image.png"); $layers[] = imagecreatefrompng

Perl GD Check If Pixel is Transparent

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 02:33:00
问题 I've been trying to solve this for a while. I have to check if a given pixel(x,y) is fully transparent. 1.How to Extract the alpha channel from a given pixel? Having an alpha channel of 127 will mean that the pixel is transparent? 2. I have tested the following code on a transparent pixel and It produces an RGB combination of a really dark(almost black) colour. I could use this as indicator, but I need a more accurate way. my $myImage = newFromPng GD::Image($path); $myImage->saveAlpha(1); my

JpGraph: How to control x/y offset, margins and color in v3.5.0b1 when using AccBarPlot?

自闭症网瘾萝莉.ら 提交于 2019-12-22 11:35:57
问题 A little background I am attempting to migrate a project built with Symfony 1.2 from one server to another. One of the functions of the project is to build a graph (originally done with JpGraph 2.3.5). The graph does not display as intended without modifications to the code and am looking for some insight on what I might be overlooking. Images are linked due to not having enough points to post. Graph Image Gallery The following graph is what is generated by the code block below <?php public

How can I tint transparent PNG files in PHP?

南楼画角 提交于 2019-12-22 10:32:42
问题 I have a transparent PNG image. The transparent areas need to remain completely transparent, but the other areas need tinting with a particular hue. What's the best way to do this using GD? Cheers, James 回答1: The above solution didn't work for me. You are filling alpha region here with red; that I believe is not the objective. Objective is to tint the rest of the image and leave the alpha unchanged. (Also, wrong use of function imagecolorallocate, you should use imagecolorallocatealpha.) I

PHP GD: The image cannot be displayed because it contains errors

我只是一个虾纸丫 提交于 2019-12-22 09:56:12
问题 I try to make Captcha via PHP GD. But unfortunately I encounter to a problem! PHP tell me: The image “http://127.0.0.1/par.php” cannot be displayed because it contains errors. My code is this <?php header ('Content-Type: image/png'); $im = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream'); $text_color = imagecolorallocate($im, 233, 14, 91); $red = imagecolorallocate($im, 255, 0, 0); for ($i=0;i<=120;$i=$i+1){ for ($j=0;$j<=20;$j=$j+1){ imagesetpixel($im, $i,$j,