Unstoppable Domains

Image resizing script

Spaceship Spaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
 
0
•••
great will look into it, thanks
 
0
•••
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
 
0
•••
what does % do?

eg: <img src="http://domain.tld/folder/image.ext" height="%" width="%" />?????
 
0
•••
<img src="http://domain.tld/folder/image.ext" height="50%" width="50%" />
 
0
•••
as elmister points out I mean use a percentage of the screen size instead of a hardened image size.
 
0
•••
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
 
0
•••
PoorDoggie said:
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.
 
0
•••
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
BillyConnite said:
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.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back