ImageCreateFromJpeg problem

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
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

ImageCreateFromJpeg problem

Post by mmc01ms »

I have created a resize_image function which i know is coded fine. However the only problem is that when i view my newsboard the image is not there. however opening notepad i can see that it has found the create path for the image and all is displayed is a white image with a red cross. I then typed the actual line of code into the browser which was

Code: Select all

http://localhost/resize_image.php?image=2.jpg
this produced

Code: Select all

Fatal error: Call to undefined function: imagecreatefromjpeg() in c:\program files\apache group\apache2\htdocs\resize_image.php on line 38
I thought that imagecreatefromjpeg was an internal function of php? full code is below any help very helpful!

Code: Select all

<?php
	
		
	$image = $_GET['image'];
	
	if (!$max_width)
		$max_width = 80;
	if (!$max_height)
		$max_height = 60;
	
	
	$size = GetImageSize($image);
	$width = $size[0];
	$height = $size[1];
	
	//find the ratio between the actual and max dimensions.
	
	$x_ratio = $max_width / $width;
	$y_ratio = $max_height / $height;
	
	if ( ($width <= $max_width) && ($height <= $max_height) ) {
		$tn_width = $width;
		$tn_height = $height;
	}
	
	else if (($x_ratio * $height) < $max_height) {
		$tn_height = ceil($x_ratio * $height);
		$tn_width = $max_width;
	}
	else{
		
		$tn_width = ceil($y_ratio * $width);
		$tn_height = $max_height;
	}
	
	$src = ImageCreateFromJpeg($image);
	$dst = ImageCreate($tn_width,$tn_height);
	ImageCopyResized($dst, $src, 0, 0 ,0 ,0, $tn_width, $tn_height, $width, $height);
	header('Content-type: image/jpeg');
	ImageJpeg($dst, null, -1);
	ImageDestroy($src);
	ImageDestroy($dst);
	
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

check your phpinfo for your php version and check your phpinfo to see if your gb libraries are enabled. As far as I know GD 2.0.15 is bundled with PHP 4.3.4 +

You may also find some of the user comments useful at http://ca.php.net/manual/en/function.im ... omjpeg.php

for example:
lordneon at deskmod dot com
23-Jun-2003 05:00
For Windows users who wants to enable the GD libary:

It took me some while to figure this out, but in the end it worked (and still does) great.

1. First download the latest (stable recommended) version of php
2. Unzip to f.ex c:\php\

3. Now you should have a file in c:\php\ that's named php.ini.dist (or something like that). Rename that to php.ini and copy it to the root of you Windows directory.

4. Open the php.ini file (the easiers way is to open the run promnt at your start menu and just type php.ini and hit enter).

5. Search (ctrl+f) for extension_dir. The default value is set to "./", make it to "./extensions"

6. Now you need to find where in the php.ini the modules for Windows is located. Search for gd.

7. Remove the ; char infront of this line: extension=php_gd2.dll

8. Try make a php script with some image functions and see if it works. F.ex $im = imageCreate("test.jpg");
If you get a message that says something like imageCreate function doesn't exist the gd libary is not loaded.

9. That's all. Have fun using GD in Windows :)
atapi103 at hotmail dot com
31-May-2003 04:14
As jpsy sugested Windows users can download the zip to get the gd2_dll extension

OR

If you already installed with the windows installer and are too lazy to get the zip you can go here

http://www.coupin.net/gd-freetype/windows.php

Download the php_gd2.dll file put it wherever you want, and change the

extension_dir=C:\php\extensions

Wherever you saved the dll to is the path you put in, remember to uncomment

extension=php_gd2.dll

Do not uncomment the one above for gd.dll (the one without the 2)
Last edited by John Cartwright on Wed Jan 05, 2005 5:16 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

out of curiousity, what version of php and gd do you have running?
Post Reply