PHP Image Resize problem

This is a discussion on "PHP Image Resize problem" within the PHP Forum section. This forum, and the thread "PHP Image Resize problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 6th, 2005, 17:16
Junior Member
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Image Resize problem

I am trying to retrieve some images from a mySQL DB, resize them in PHP, in proportion, with the following function. This is working fine when testing on my local machine. However, when I load it to the web I get the default width($mw) but no height (IE draws a 1m image height). Check it out at
http://www.freewaymedical.co.uk/prot...dex.php?cat=ch

Thinking it must be differing PHP versions on local machine and web hosts. Is there anything I can edit in my code for a fix?

Code: Select all
//n=image name
//mh=maxHeight
//mw=maxwidth
function resizeGetSize($n, $mh, $mw){
//test for type String or object. This is so the function can handle
//objects directly
	//getimagesize() returns width and height in an array
	$imgSize = getimagesize($n); 
	
	$prop = $imgSize[0] / $mw;
	$newHeight=$imgSize[1] / $prop;
	
	//initialize a var to hold the max width of the img
	$newWidth=$mw;
	$decrement=5;

		//loop until the height of the image is less than 180 (so it fits in the cell with no fuss)
		while($newHeight>$mh){

			$prop = $imgSize[0] / ($newWidth-$decrement);
			$newHeight=($imgSize[1] / $prop);
			//take off 5 px at a time until the pics height fits in the table height
			$newWidth=$newWidth - $decrement;

		}
	//return in string that can  be used directly in function
	return "width=\"$newWidth\" height=\"$newHeight\"";
}
Any help would be much appreciated.
Reply With Quote

  #2 (permalink)  
Old Jun 6th, 2005, 17:51
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
You need to try to debug this - where does the height value dissapear? Is it at the very beginning when you call getimagesize($n);, or later on in one of the maths bits?
Reply With Quote
  #3 (permalink)  
Old Jun 6th, 2005, 18:06
Junior Member
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
I am more than happy to get stuck in to the debugging-it just threw me that it works locally but not on host. Thought that someone may have noticed something obvious.

I will try debugging on the host.

Any more suggestions in the meantime would be appreciated.

Cheers
Reply With Quote
  #4 (permalink)  
Old Jun 6th, 2005, 18:48
Junior Member
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
I took your tip and did some debugging-For some reason I needed to give an absolute path (http://...) rather than relative (../images/)

This has done the trick.

Cheers
Reply With Quote
  #5 (permalink)  
Old Jun 6th, 2005, 21:57
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Aaah, that makes sense if the file is accessed via HTTP...?
Reply With Quote
  #6 (permalink)  
Old Jun 7th, 2005, 07:29
Junior Member
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah that's right. Can you explain why HTTP needs an absolute path?
Reply With Quote
  #7 (permalink)  
Old Jun 7th, 2005, 11:34
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Because the server has no way of knowing where the relative path starts from... it's like you typing /images/grass.gif into your internet browser.
Reply With Quote
Reply

Tags
php, image, resize, problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resize dynamically loaded image nate2099 Flash & Multimedia Forum 2 Aug 31st, 2007 22:36
word resize problem in frameset jacobds Web Page Design 4 Feb 13th, 2007 22:21
Resize image-how to get lenght of image nicetomeetu PHP Forum 9 Sep 19th, 2006 22:39
Resize image-how to get lenght of image nicetomeetu Introduce Yourself 5 Sep 18th, 2006 14:08
resize problem somsahi Web Page Design 5 Aug 22nd, 2006 20:34


All times are GMT. The time now is 20:51.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43