| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Soon to be RICHdoggie! | 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 |
| |
| | #2 (permalink) |
| New Member | 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) |
| Senior Member | 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) | |
![]() | Quote:
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; ?> | |
| |
| | #10 (permalink) | |
| Soon to be RICHdoggie! | 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:
| |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |