PHP Image Scaler
PHP Code
+ 0 likes
Please Register to submit score.
| Average Score | 4.0 |
| Scores Submitted | 2 |
| Date Added | Jun 07, 2008 |
| Last Updated | Jun 10, 2008 |
Introduction
This snippet is fantastic for galleries, cutouts, small webpages, limited sized webpage, forums, anywthing where users can manually edit the webpage and create a "possibility" of screwing it up, this should help!
This does not distort images, whatsoever! it rescales the width and height according to the maximum width/height you allocate.
I am working on developing a function which will cover both in one snippet, but for now, this is what i have :p
How it works (examples)
Insert the function in-between the img tags where width & height paramaters usually would go;
| Code: |
| <?php $img = 'images/myfiles/image1.jpg'; echo '<img src="' .$img. '" ' .width_scale($img,"200"). '>'; ?> |
PHP Snippet:
PHP Image Scaler
Posted on Jun 8, 2008 4:01 am
Posted on Jun 8, 2008 4:01 am
someone go learn PHP and comment ! :P
PHP Snippet:
PHP Image Scaler
Posted on Jun 8, 2008 5:24 am
Posted on Jun 8, 2008 5:24 am
rofl, nice, haven\'t been able to try it as i\'m doing school work atm. But it looks nice. :) good job
PHP Snippet:
PHP Image Scaler
Posted on Jun 8, 2008 7:20 am
Posted on Jun 8, 2008 7:20 am
lol, no worries.
Furbs, i was wondering if i can catch u on msn/irc sometime, i need a bit of help with my gallery lol
Furbs, i was wondering if i can catch u on msn/irc sometime, i need a bit of help with my gallery lol
PHP Snippet:
PHP Image Scaler
Posted on Jun 8, 2008 8:54 am
Posted on Jun 8, 2008 8:54 am
Sure Ballopah, you have me on MSN, so might as well use that ;)
PHP Snippet:
PHP Image Scaler
Posted on Jun 8, 2008 9:37 am
Posted on Jun 8, 2008 9:37 am
Hehe, yeesh. problem sorted now anyways lol
PHP Snippet:
PHP Image Scaler
Posted on Jun 10, 2008 11:16 am
Posted on Jun 10, 2008 11:16 am
Oops, noticed a little error. :D
corrected $width to 100 .. i never understood percentages >.>
Kidding ^, they\'re easy .. :D
corrected $width to 100 .. i never understood percentages >.>
Kidding ^, they\'re easy .. :D
PHP Snippet:
PHP Image Scaler
Posted on Jun 16, 2008 11:39 am
Posted on Jun 16, 2008 11:39 am
Just a note: resizing images on \'the fly\' is resource intensive.
PHP Snippet:
PHP Image Scaler
Posted on Jun 16, 2008 11:52 am
Posted on Jun 16, 2008 11:52 am
On a large scale .. Maybe. But on a small scale, not soo bad.
Do you mean the getimagesize?
Do you mean the getimagesize?
PHP Snippet:
PHP Image Scaler
Posted on Aug 25, 2008 11:07 pm
Posted on Aug 25, 2008 11:07 pm
Yeah, I would like to see a single function rather than two.
PHP Snippet:
PHP Image Scaler
Posted on Aug 25, 2008 11:21 pm
Posted on Aug 25, 2008 11:21 pm
Would this work (not a big PHP user):
Syntax: image_scale($img,"200","250")
Example:
Syntax: image_scale($img,"200","250")
Example:
| Code: |
| <?php $img = 'images/myfiles/image1.jpg'; echo '<img src="' .$img. '" ' .width_scale($img,"200","250"). '>'; ?> |
| Code: |
| ////////////////////////////////////////////////////////////// // Scale images by width+height // ////////////////////////////////////////////////////////////// function image_scale($file,$maxwidth,$maxheight) { list($width,$height) = getimagesize($file); if (($width > $maxwidth) && ($height > $maxheight)) { $new_width = $maxwidth; $new_height = $maxheight; $dec_perw = $new_width / $width * 100; $dec_perh = $new_height / $height * 100; $new_width = $width / 100 * $dec_per; $new_height = $height / 100 * $dec_per; return 'width="' .$new_width. '" height="' .$new_height. '"'; } else { return 'width="' .$width. '" height="' .$height. '"'; } } |
PHP Snippet:
PHP Image Scaler
Posted on Aug 25, 2008 11:26 pm
Posted on Aug 25, 2008 11:26 pm
tye did a nice image scaler a while back, http://www.hawkee.com/snippet/844/
PHP Snippet:
PHP Image Scaler
Posted on Aug 25, 2008 11:27 pm
Posted on Aug 25, 2008 11:27 pm
Yea, that one is a lot more advanced, especially since it not only gets the job done great, but it's also more performance-optimized.








