github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

maxim / smart_resize_image

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 17
    • 7
  • Source
  • Commits
  • Network (7)
  • Issues (3)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

PHP function for image resizing that does what you think it should, the right way. — Read more

  cancel

http://mediumexposure.com/techblog/smart-image-resizing-while-preserving-transparency-php-and-gd-library

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fix link. 
maxim (author)
Thu Jan 29 07:25:51 -0800 2009
commit  3c122a8837015f4587219e05019005b13e0f032a
tree    0ea6ff107eb9b6803ad45c138aa417f54767938f
parent  7673665e58406b3e3a3c877f461ae9891e5b7f59
smart_resize_image /
name age
history
message
file README.rdoc Thu Jan 29 07:25:51 -0800 2009 Fix link. [maxim]
file smart_resize_image.function.php Thu Jan 29 00:29:48 -0800 2009 Add formatting enhancements. [maxim]
README.rdoc

smart_resize_image

Should be easy to find, right? All you want is a function that resizes an image to constraints (doesn’t care if it should scale up or down), with possibility to select if you want to keep it proportional, and possibility to use either width or height as the constraint. Also, you want it to preserve transparency damn it! Surprisingly, I was unable to find a good function that does all that, so I decided to attempt writing it. This should do it.

Note: Original announcement and comments for the function are available at mediumexposure.com/techblog/smart-image-resizing-while-preserving-transparency-php-and-gd-library

Features/Usage:

    * If you pass width as 0 (zero) -- this function will disregard width, and use height as constraint. Same vice versa.
    * If you set "proportional" to false - the function will simply stretch (or shrink) the image to its full constraints.
    * If one of the dimensions is set to zero, and proportional set to "false" - then the image will be forced to stretch or shrink the other dimension, and disregard the zeroed dimension (leave it the same).
    * If proportional is set to true - the image will resize to constraints proportionally, once again, with possibility to have either width or height set to zero.
    * The function can use either linux "rm" command, or php @unlink. Most probably you don't need to ever use that flag, but on some setups - @unlink won't work due to user access restrictions.
    * The function will simply replace the file that you give it, with the resized file.
    * The function supports gif, png, and jpeg, and preserves the transparency of gif and png images.
    * Tested on GD version 2.0.28 only.

Essentially, everything happens just as logically expected. Please, if you see anything wrong, and you know ways to enhance, or optimize it, let me know.

Update

There is a new parameter "output" which can be set to either

    * "file" - overwrite the given file (default)
    * "browser" - output image through http - with correct mime type
    * "return" - return GD Library Image object
    * or any filename of choice - save changed version to output path

Update

There is another new parameter "delete_original". Speaks for itself.

License

Copyright © 2008 Maxim Chernyak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server