NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Image resizing script

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-12-2006, 02:08 PM THREAD STARTER               #1 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Image resizing script


I have seen it around places. I want to be able to display an image like this:
????: NamePros.com http://www.namepros.com/programming/196673-image-resizing-script.html

<img src="displayimage.php?image=http://www.namepros.com/images/npblogo2.gif" />

or something that will resize the image to fit a page. I could resize http://www.namepros.com/images/npblogo2.gif by using the height and width attributes, but php keeps most of the quality.

If someone could also show me how to make it so that it resizes to fit the size of the page, that would be great.
(eg: a user whos browser is not maximised won't have scroll bars - also, as they change the size of the browser, it changes size too. like on google maps)

Thanks a lot
Tom
PoorDoggie is offline  
Old 05-12-2006, 07:39 PM   #2 (permalink)
New Member
Join Date: Apr 2006
Posts: 18
elmister is an unknown quantity at this point
 



If you are familiar with PHP you should take a look at GD functions

Something as easy as:

$im = @imagecreatefromgif ($imgname); /* Attempt to open
list($width, $height, $type, $attr) = getimagesize($imgname);

$newim= imagecreate($new_width,$new_height);

imagecopyresampled($newim, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagegif($newim);


i've did this quickly, you could add some code to check if the image is a jpeg or a gif, and choose the corresponding jpeg functions of gif functions.
It will fail with big images, because of memory limitations on PHP
elmister is offline  
Old 05-13-2006, 07:25 AM THREAD STARTER               #3 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



great will look into it, thanks
PoorDoggie is offline  
Old 05-13-2006, 08:06 AM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
GD will not be able to do this unless you pass it the size of the page. PHP has no idea how big a page is as it is a server side technology. It could most likely be done in javascript, on the other hand you could use ajax along with php (I am assuming in this case that javascript has access to the screen resolution).

Alternatively could you not just use a % for the size in the img src tag
Peter is offline  
Old 05-13-2006, 03:38 PM THREAD STARTER               #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



what does % do?

eg: <img src="http://domain.tld/folder/image.ext" height="%" width="%" />?????
PoorDoggie is offline  
Old 05-13-2006, 05:43 PM   #6 (permalink)
New Member
Join Date: Apr 2006
Posts: 18
elmister is an unknown quantity at this point
 



<img src="http://domain.tld/folder/image.ext" height="50%" width="50%" />
elmister is offline  
Old 05-13-2006, 07:46 PM   #7 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
as elmister points out I mean use a percentage of the screen size instead of a hardened image size.
Peter is offline  
Old 05-14-2006, 03:14 AM THREAD STARTER               #8 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



oh right... lol

I would you see, but the point is that I don't want any loss of quality. If it is a very big image, and I scale it right down it goes funny. Thanks anyway.

Tom
PoorDoggie is offline  
Old 05-14-2006, 03:57 AM   #9 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Originally Posted by PoorDoggie
oh right... lol

I would you see, but the point is that I don't want any loss of quality. If it is a very big image, and I scale it right down it goes funny. Thanks anyway.

Tom
If you are wanting to recsize an image without loss of quality on the client-side, it can't be done at all (thats without any loss of quality).

It can be done on the server-side, but this means that each time the page is resized just by on pixel, it will request a new image from the server, which must be processed and saved. This is waaayyy to resourceful, and would simply result in your server load going from 1% to 100%, and leaves your websites very vulnerable to ddos attacks.
????: NamePros.com http://www.namepros.com/showthread.php?t=196673

Therefore, you cannot resize images without loss of quality as you want. Google earth uses a very different method to what you want...

You MAY be able to do this in a flash file, but I've never tried it.

All the best!
Rhett.
BillyConnite is offline  
Old 05-14-2006, 06:57 AM THREAD STARTER               #10 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



ok. I have done it using the 100% thing. The image quality is not that bad too be fair.

Thanks for all your help
Tom
Originally Posted by BillyConnite
If you are wanting to recsize an image without loss of quality on the client-side, it can't be done at all (thats without any loss of quality).

It can be done on the server-side, but this means that each time the page is resized just by on pixel, it will request a new image from the server, which must be processed and saved. This is waaayyy to resourceful, and would simply result in your server load going from 1% to 100%, and leaves your websites very vulnerable to ddos attacks.

Therefore, you cannot resize images without loss of quality as you want. Google earth uses a very different method to what you want...

You MAY be able to do this in a flash file, but I've never tried it.

All the best!
Rhett.
PoorDoggie is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:42 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger