Cesar D. Rodas, web development. Technology news. PHP, MySQL, Apache, C, Bash, ASM

Resize images

Some times web sites require image resize, let’s say… upload, resize and display image. That process is harder to handle by PHP (internally) because resize an image require a lots of computers resources (CPU, memory, time), so for a good results there must exist a cache system, which simply is do not re-do what is done.

On work I need to do something like that and I was a little tired for rewrite my own class, so I google-up and I’ve a class that feed my needs. Easy to implement, just a few of lines to write for made it works!, and resize image is saved into a folder ( a cache system).

Another good issue that I’ve seen in this class is the possibility to emblemed water images.

Examples:

<?php
include “SmartImage.class.php”;

$img = new SmartImage(“newimages/new01.jpg”);
// Resize and save to file
// the true value means to cut the image
$img->resize(400, 220, true);
$img->addWaterMarkImage(“images/smartimage.gif”);
$img->saveImage(“newimages/new03.jpg”, 85);
?>

The above code will transform this image:

Into this:

I really like this class not only because works fine for me and is easy to implement, also I liked an very much this class for it license (LGPL) which gives me the freedom to include into my projects without share the code of my proyect (sometimes we cannot share the code, but I usually do). For that reason, most of my proyects are public domain or under BSD License.

DOWNLOADLogo

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. Digg del.icio.us StumbleUpon Technorati BlinkList Furl NewsVine Reddit

3 Responses to “Resize images”

  1. Cesar D. Rodas Says:

    I wanna give thanks to Alessandro Coscia for this class… :-D

    I think most programmers should write useful class and share it…

  2. Lamonte @phpdiscovery.com Says:

    So can you add a custom text on web pages using this class? It sounds good :).

  3. admin Says:

    You can add a watermark image. :-)

Leave a Reply


Fatal error: Call to undefined function display_cryptographp() in /home/.schmuckie/saddor/cesarodas.com/wp-content/themes/first-spring-10/comments.php on line 94