How to check if GD2 extension is loaded?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

How to check if GD2 extension is loaded?

Post by WaldoMonster »

For the GD extension this code works:

Code: Select all

<?php
if (!extension_loaded('gd')) echo('GD extension not loaded');
?>
But how can I check if GD2 (on windows) is loaded?

Another question.
What was the first release above PHP 4.1.0 that came with the GD2 extension (windows compile)?

Thanks for the help.
number8
Forum Newbie
Posts: 7
Joined: Tue Nov 30, 2004 8:51 am
Location: VirtualCity, Neural Networks str. 11

Post by number8 »

You can see the names of various extensions by using phpinfo() or if you're using the CGI or CLI version of PHP you can use the -m switch to list all available extensions

-Or-

Use print_r(get_loaded_extensions()); to get all loaded extensions.

I hope this will show you the right way 8)
Last edited by number8 on Tue Nov 30, 2004 9:39 am, edited 1 time in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or:

Code: Select all

print_r(gd_info());
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Thanks kettle_drum,

Code: Select all

<?php
$gd_info = gd_info();
echo $gd_info['GD Version'];
?>
returns something like:

Code: Select all

bundled (2.0.28 compatible)
I'm not so good with preg_match, how can I check if it is version 2 or newer?
Checking if 'imagecreatetruecolor' function exit, is this a good alternative?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

The gd_info() function is only available in PHP v4.3 and above, PHP v4.3 only has the imagecreatetruecolour function available if G.D 2 is loaded so you can use a standard function_exists() to determine if GD2 is loaded.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How to check if GD2 extension is loaded?

Post by pickle »

Couldn't you just go:

Code: Select all

<?php
if (!extension_loaded('gd2')) echo('GD extension not loaded');
?>
??
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Re: How to check if GD2 extension is loaded?

Post by WaldoMonster »

pickle wrote:Couldn't you just go:

Code: Select all

<?php
if (!extension_loaded('gd2')) echo('GD extension not loaded');
?>
??
That doesn't work.
Otherwise I would use that :wink:
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

redmonkey wrote:The gd_info() function is only available in PHP v4.3 and above, PHP v4.3 only has the imagecreatetruecolour function available if G.D 2 is loaded so you can use a standard function_exists() to determine if GD2 is loaded.
I will go for:

Code: Select all

<?php
if (!function_exists('imagecreatetruecolor')) echo('GD2 extension not loaded');
?>
Thanks
Post Reply