Questions tagged [php-gd]

The PHP GD class contains built in image manipulation for PHP versions 4.3 and up.

The PHP GD class contains built in image manipulation for versions 4.3 and up. This class is commonly used for:

  • Adding filters to images
  • Adding watermarks to images
  • Changing image size for upload
  • Outputting an image to the buffer
  • Creating images on the fly (e.g. captcha verification)

A download of the library can be found at https://bitbucket.org/pierrejoye/gd-libgd/downloads

370 questions
5
votes
3 answers

Resizing font size and padding using gd to create a dynamic bar chart

Inspired by this code, I am trying to create a simple bar chart able to dynamically create, resize both bars and texts depends on the the $data, $height and $weight:
celsowm
  • 846
  • 9
  • 34
  • 59
5
votes
1 answer

Internal gd font () not available use only 1-5

I am using Laravel framework and image/intervention library for generating images with dynamic data. The code is running perfectly fine on my local machine but as soon as I upload it on aws ubuntu instance it is showing error like Internal gd font()…
sajag16642
  • 75
  • 2
  • 9
5
votes
4 answers

Center text on image using PHP GD

So I am creating a banner generator. I will be adding text in the middle, but would like it to be exactly in the center. I know that imagettftext can be used to write onto the banner, but that won't center it. A likely solution could be to find the…
ThePixelPony
  • 721
  • 2
  • 8
  • 30
4
votes
1 answer

PHP-GD: preserve half-transparent areas

I'm in need of a generic image upload for a PHP site. Photos and Logos should be re-sized to a certain extend to make sure they're not too big and fit the design. I'm trying it with this code: function resize($width,$height) { $new_image =…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
4
votes
2 answers

Max crop area for a given image and aspect ratio

Is there any PHP/GD function that can calculate this: Input: image width, image height and an aspect ratio to honor. Output: the width/height of the max centered crop that respects the given aspect ratio (despite image original aspect…
user1098965
4
votes
2 answers

Transparent PNG over JPG in PHP

What seems to be simple, isn't :( I'm trying to add something like a watermark (transparent png) on an image (jpg). This is the code I'm using: $width = 800; $height = 600; $bottom_image = imagecreatefromjpeg("portrait1.jpg"); $top_image =…
ekstrakt
  • 900
  • 1
  • 12
  • 28
4
votes
1 answer

Compress & resize images using PHP GD lib not working for png and weird results for jpg

I am trying to compress & resize my images using the php GD library. Nearly every answer on SO and everywhere else is the same, but for my solution, the PNG's are not being correctly transformed, and some jpg's are giving bizarre results. This is…
Dennis
  • 3,044
  • 2
  • 33
  • 52
4
votes
2 answers

How to merge multiple images and text into single image?

I have multiple PNG images inside a div, those images are PNG and presents as single image for user depending on custom options he/she has selected. Also, adding text is also enabled as other feature, which allows a div with texts to add above of…
Suman KC
  • 3,478
  • 4
  • 30
  • 42
4
votes
0 answers

Tamil unicode font in php gd

Many people have asked similar questions. Most of them are advised to use the right fonts. I tried most of the available tamil utf fonts. I haven't found complete solution. After from fonts, it looks like wee need to swap the text. கு -> It is a…
agriz
  • 689
  • 1
  • 6
  • 18
4
votes
2 answers

imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error - Laravel

I have 2 below routes :- Route::get('resize/avatar', function() { $image = 'avatar.jpg'; $target_filename_here = 'thumbnail_'.$image; $ffs = imagecreatefromjpeg($image); $size = getimagesize($image); $dst =…
user3767643
  • 674
  • 2
  • 9
  • 25
4
votes
2 answers

imagecreatefromstring - catch fail - PHP

I'm trying to detect if an image is an image when given a URL. To save an image from a url I used the following: // create the image and save it $imagefile = $URL; $resource = imagecreatefromstring(file_get_contents($imagefile)); // X amount of…
Lovelock
  • 7,689
  • 19
  • 86
  • 186
4
votes
1 answer

How to achieve the reverse effect of imagecreatefromstring in PHP?

How can I get a base64 string from an image resource in PHP? Note however, I made the image on the fly, so no URL exists. Here is what I've tried, but it doesn't work: echo 'data:image/png;base64,'.base64_encode($img); This gives an error: Warning:…
4
votes
3 answers

What's wrong with imagecreatefromstring function?

What is wrong with this code?
ptCoder
  • 2,229
  • 3
  • 24
  • 38
4
votes
1 answer

Using PostGis' ST_AsPNG() Output to Create Image with PHP

I'd like to create an image based on raster output I'm building from a PostgreSQL spatial database. I have a query: SELECT ( ST_AsPNG( ST_AsRaster( geom, 1.5::double precision, 2::double precision, 11, 11, '8BUI', 100, 0, 0,…
Zachary Schuessler
  • 3,644
  • 2
  • 28
  • 43
4
votes
2 answers

How to load an image resource from a URL into a PHP script, using cURL?

I'm using the Google Charts service to generate some QR codes that I afterward need to manipulate (e.g. rotate, scale) in a PHP script and merge with other images to generate one final image. How do I correctly load such a resource (from a URL) into…
Andrei Oniga
  • 8,219
  • 15
  • 52
  • 89
1 2
3
24 25