can't draw images

Problems with the Windows version of XAMPP, questions, comments, and anything related.

can't draw images

Postby gmeyers1 » 08. April 2023 23:25

This simple code just draws a tiny white square (about 10 by 10) centered in a black screen. It should draw a 150 by 150 blue square centered in a black screen.

<?php
header('Content-type: image/png');
$png_image = imagecreate(150, 150);
imagecolorallocate($png_image, 15, 142, 210);
imagepng($png_image);
imagedestroy($png_image);
?>
gmeyers1
 
Posts: 9
Joined: 08. March 2023 19:57
XAMPP version: 8.2.0
Operating System: Windows 11

Re: can't draw images

Postby Nobbie » 08. April 2023 23:41

And what is the question?
Nobbie
 
Posts: 13214
Joined: 09. March 2008 13:04

Re: can't draw images

Postby gmeyers1 » 09. April 2023 00:31

The question is why I get a 10x10 white square instead of a 150x150 blue square as indicated in the code
gmeyers1
 
Posts: 9
Joined: 08. March 2023 19:57
XAMPP version: 8.2.0
Operating System: Windows 11

Re: can't draw images

Postby Nobbie » 09. April 2023 12:47

I dont know, i get a blue square 150x150 as designed. Maybe you get any kind of error, check your error_log and access_log. Finally, how do you execute the script?

You should also consider that you may have a .htaccess which does a redirect or so, actually we dont know anything about your installation. There may also miss a graphic library or so. Hard to say without knowing anything. I have a clean Xampp installation and this script runs flawlessly.
Nobbie
 
Posts: 13214
Joined: 09. March 2008 13:04

Re: can't draw images

Postby Froosh » 09. April 2023 14:26

Interesting. I was curious, and tried on my system and got a small square with the incorrect color. I inspected the generated html, and explicitly set the height and width of the element, and that showed that no image was actually generated by the php code provided.

A bit of digging let me to other samples on the PHP site, and the ones I tried did not work either. One of the samples, a HTML page using PHP and imagecreate() generated a PHP fatal error. Following that error message led to a stackoverflow post that indicated to check php.ini and ensure "extension=gd" line is not commented out, which in my install was the case. I also noticed that my Apache error.log indicated that imagecreate was not found.

After uncommenting that "extension=gd", and restarting Apache, I know see blue 150x150 square and text.

As Nobbie mentioned, there could be other causes in your particular situation. The logs are your friend, especially if you are running code based on an example that might be masking the underlying error.
User avatar
Froosh
 
Posts: 138
Joined: 27. March 2022 17:56
XAMPP version: 8.2.0
Operating System: Windows 11 Pro

Re: can't draw images

Postby gmeyers1 » 09. April 2023 14:52

error log said imagecreate was not found. I then edited the php.ini file in the extensions section and uncommented the line extension=gd, restarted apache and that solved the problem. Thanks for your help.
gmeyers1
 
Posts: 9
Joined: 08. March 2023 19:57
XAMPP version: 8.2.0
Operating System: Windows 11


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 123 guests