1

Can somebody help me to show the problem of my code? This is the output when I write this code: In this case I have installed GD on php

enter image description here

<?php 
//create the canvas
$myImage = ImageCreate(150,150);

//setup some colors

$black  = ImageColorAllocate($myImage, 0, 0, 0);
$white  = ImageColorAllocate($myImage, 255, 255, 255);
$red    = ImageColorAllocate($myImage, 255, 0, 0);
$green  = ImageColorAllocate($myImage, 0, 255, 0);
$blue   = ImageColorAllocate($myImage, 0, 0, 255);

//draw some rectangles

ImageRectangle($myImage, 15, 15, 55, 85, $red);
ImageRectangle($myImage, 55, 85, 125, 135, $white);

// output the image to the browser
header("Content-type: image/gif");
ImageGif($myImage);

//clean up after yourself
ImageDestroy($myImage);

?>

Expected Output: enter image description here

Can you show me how to solve it? Thank you!

  • Works fine for me. Have you installed and enabled the `gd` extension? Perhaps this is throwing errors that you can't see – Phil Feb 15 '23 at 04:21
  • I took your code without any modification, added it to an `index.php` file in a `php:8.1-alpine` Docker image, installed GD through `apk add zlib-dev libpng-dev && docker-php-ext-configure gd && docker-php-ext-install gd`, ran `php -S 0.0.0.0:8000` and opened `http://localhost:8000` in my browser and got the correct image. So even if you have no errors reported, this is simply not reproducible – Phil Feb 15 '23 at 06:13
  • No repro ~ https://codesandbox.io/p/sandbox/small-shape-f0n7m2?file=%2Findex.php – Phil Feb 15 '23 at 06:35

0 Answers0