groups

name language licence
TINYURL ON EVERY WORDPRESS-POST PHP BSD
Display an External RSS Feed PHP BSD
Multiple backgrounds with CSS3 CSS BSD
Create A Maintenance Page For Your WordPress Blog HTML BSD
Display Related Posts Without A Plug-In PHP BSD
Resize Images On The Fly PHP BSD
opacity background PHP BSD
Untitled Snippet PHP BSD

< 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 >



language: PHP
licence: BSD

Resize Images On The Fly

options: view full snippetsend to code collector
//The problem. When you use thumbnails on your blog’s home page or even images in posts, having to manually resize them is boring and wastes a lot of time. So, why not use the power of PHP to do it?
The solution. To achieve this hack, just follow these simple steps:
Get this script and save it on your computer (I’ll assume you’ve named it timthumb.php).
Use an FTP program to connect to your server and create a new directory called scripts. Upload the timthumb.php file to it.
Once done, you can display images like so:

<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="Screenshot" />


//Code explanation. The timthumb.php script use the PHP GD library, which allows you to manipulate images dynamically with PHP. GD is installed by default on all servers running PHP5. If you’re not running PHP5, you’ll have to check if GD is installed before using this script.
The timthumb.php file gets the parameters you’ve passed to it (image URL, width and height) and uses it to create a new image with your stated dimensions. Once that’s done, the image is returned to you.
	
(Continues...)