| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #2 (permalink) |
| New Member Join Date: Apr 2006
Posts: 18
![]() | 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 |
| |
| | #4 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #9 (permalink) | ||||
![]() Join Date: Jul 2005 Location: Coffs H, Australia
Posts: 3,456
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________ Free Forums / GoDaddy Coupon Codes (NEW DOMAIN!) / Free Arcade Script / <?='Your computer is '.(1?fine:broken).'.'?> | ||||
| |
| | THREAD STARTER #10 (permalink) | ||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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
| ||||
| |