Words from Alejandro U. Alvarez
General talk
A place for all random thoughts and ideas that come across my mind and I can’t find the right “category” to put in…
PHP easy image editing:
Apr 9th
Do you have a picture upload and you don't know how to easily resize/edit the uploaded images?
Well here is a solution for php that will make your life really easy!
It is called Asido, so you may go and download their code, to follow this tutorial.
First of all I'll suppose you already know how to upload an image. I may write an article about it someday, but for now I'll assume you do know.
So once you have successfully uploaded and moved your picture to its final destination, include Asido's class object, then chose a driver (the gd driver works fine), and then chose file names. You can leave in both the same, so that all changes are made to the uploaded image and stored in the uploaded image.
include('class.asido.php'); asido::driver('gd'); $i1 = asido::image($new_file_name,$new_file_name);
And now you can start working:
Resizing your image:
With Asido resizing an image is as easy as this:
Resizing proportionally using the width:
Asido::width($i1, 200); $i1->save(ASIDO_OVERWRITE_ENABLED);
Where 200 is the new width, "$i1->save(ASIDO_OVERWRITE_ENABLED);" saves the image.
You can achieve the same effect using "Asido::resize($i1, 200, 0);"
Resizing proportionally using the height:
Asido::height($i1, 200); $i1->save(ASIDO_OVERWRITE_ENABLED);
Where 200 is the new height.
You can achieve the same effect using "Asido::resize($i1, 0, 200);"
Adding a watermark
A very useful tip when you are developing a public picture upload, to get some marketing
So you need a png image with your watermark, for the example I named it watermark.png
asido::watermark($i1, 'watermark.png'); $i1->save(ASIDO_OVERWRITE_ENABLED);
You can place the watermark wherever you want in the original pic, just use one of the following constants:
ASIDO_WATERMARK_TOP_LEFT, ASIDO_WATERMARK_TOP_CENTER, ASIDO_WATERMARK_TOP_RIGHT, ASIDO_WATERMARK_MIDDLE_LEFT, ASIDO_WATERMARK_MIDDLE_CENTER, ASIDO_WATERMARK_MIDDLE_RIGHT, ASIDO_WATERMARK_BOTTOM_LEFT, ASIDO_WATERMARK_BOTTOM_CENTER, ASIDO_WATERMARK_BOTTOM_RIGHT and ASIDO_WATERMARK_TILE
Other features
With this great image handler you can do all of the following actions:
- Stretch
- Fit
- Frame
- Convert
- Rotate
- Flip
- Flop
- Crop
- Copy
- Grayscale
Visit their feature list for full support on the above actions.
If you have any questions please comment!

