[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-12-2006, 01:08 PM   #1 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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:

<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, 06:39 PM   #2 (permalink)
New Member
 
Join Date: Apr 2006
Posts: 15
135.70 NP$ (Donate)

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, 06:25 AM   #3 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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, 07:06 AM   #4 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 02:38 PM   #5 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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, 04:43 PM   #6 (permalink)
New Member
 
Join Date: Apr 2006
Posts: 15
135.70 NP$ (Donate)

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, 06:46 PM   #7 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 02:14 AM   #8 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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, 02:57 AM   #9 (permalink)
 
BillyConnite's Avatar
 
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,107
47.00 NP$ (Donate)

BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future

Wildlife Parkinson's Disease Parkinson's Disease
Quote:
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.

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.
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline  
Old 05-14-2006, 05:57 AM   #10 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
 
Join Date: Jan 2005
Location: UK
Posts: 2,390
316.50 NP$ (Donate)

PoorDoggie 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
Quote:
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

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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:55 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85