Google Answers Logo
View Question
 
Q: Problems using PHP and the GD Library ( No Answer,   3 Comments )
Question  
Subject: Problems using PHP and the GD Library
Category: Computers > Internet
Asked by: brandonnimon-ga
List Price: $8.00
Posted: 30 Mar 2004 13:26 PST
Expires: 29 Apr 2004 14:26 PDT
Question ID: 322567
I have been programming for close to eight years now, have been using
computers for as long as I can remember; for the most part I've been
able to figure out anything on the computer.

But I have only been into PHP for a little less than a year, and have
just (in the past month) realized I need an automated image editing
program for my work.
I am currently developing a photo-based site, this is still in alpha
form, so ignore it's UI, it is no where close to what it is going to
look like.

I tried to do as much research as possible about GD2, but could not succeed.
I'm using Apache 1.3.29 and PHP 4.3.5 (non-installation --if that
makes a difference) on Windows XP; and GD library (version 2.0.17 -- I
think...whatever comes with PHP 4.3.5).

I have the GD2 extension in the PHP.ini file, and it seems to be
accessing the .dll fine, but when I try to use any of the GD commands
I get weird results. It would be best to show you. I have, on a
previous version of my site, a screen shot of what I get: 
http://24.127.21.245/osp/photo2.php?img=error_ah28944473.jpg there is
also another screen shot on the site of something else I got. The
source I used to get these results can be found at
http://24.127.21.245/osp/resizing.zip. If you look at the file in
there, you will see that I have many versions of code that I'm trying
to get any type of results from. And the PHP settings I have currently
can be found at http://24.127.21.245/osp/phpsettings.zip.

If for any reason you need to log in to test something on the site,
username: google --password: questions  (I don't care if "the world"
can see this; when I get my answers this /osp/ site will go away).

So my main question (to summerize), I want to know why I am getting
these weird results and no the images I want. And maybe you can write
a short script to give me an example of how to resize an image (one
that works independantly...just enter the images dir/name).

Thanks,
Brandon
Answer  
There is no answer at this time.

Comments  
Subject: Re: Problems using PHP and the GD Library
From: redbav-ga on 05 Apr 2004 07:57 PDT
 
// this script resizes an image '/tmp/icon.jpg'.
		// result image: max height=100, max width=200;
		
		$f_src = '/tmp/icon.jpg'; // modify it
		$f_dest = '/tmp/resized.png';// modify it
		$newW=200; // modify it
		$newH=100; // modify it
		 
		$size = getimagesize($f_src);
		if($size[2]==1)	$srcImage = imagecreatefromgif($f_src);
		if($size[2]==2)	$srcImage = imagecreatefromjpeg($f_src);
		if($size[2]==3)	$srcImage = imagecreatefrompng($f_src);
	
		$srcW = ImageSX($srcImage);
		$srcH = ImageSY($srcImage);
		
		$ratioW = $newW ? $srcW/$newW : 1;
		$ratioH = $newH ? $srcH/$newH : 1;
		
		if($srcW <= $newH && $srcW <= $newW)
		{
			$destW = $srcW;
			$destH = $srcH;
		}	
		elseif ($ratioW < $ratioH) {
			$destW = floor($srcW/$ratioH);
			$destH = $newH ? $newH : $srcH;
		}
		else {
			$destW = $newW ? $newW : $srcW;
			$destH = floor($srcH/$ratioW);
		}
		$destImage = imagecreatetruecolor($destW, $destH);
		imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destW,
$destH, $srcW, $srcH);
		ImagePng ($destImage,$f_dest);
		ImageDestroy ($srcImage);
		ImageDestroy ($destImage);

		// now copy $f_dest to any place in DOCUMENT_ROOT...
Subject: Re: Problems using PHP and the GD Library
From: brandonnimon-ga on 22 Apr 2004 18:58 PDT
 
I still haven't recieved an answer to the original question, but after
installing PHP 4.3.6, it works fine. Thank you for the help, check out
the site to see what I used it for.

-Brandon
Subject: Re: Problems using PHP and the GD Library
From: brandonnimon-ga on 22 Apr 2004 19:11 PDT
 
Nevermind, I'm in the middle of developing some stuff, so don't check
out the site. I hope in the long run it will be larger, and you may
see the final product, which will be much more impressive than what is
available for viewing now.

-Brandon

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy