[x]

deviantART

 

Creative Commons License
Some rights reserved. This work is licensed under a
Creative Commons Attribution 3.0 License.
Details
Submitted: March 19, 2007
File Size: 1.8 MB
Image Size: 1.8 MB
Resolution: 1275×2891
Comments: 10
Favourites & Collections: 2 [who?]

Views
Total: 244
Today: 0

Downloads
Total: 2
Today: 0

Embed


Thumb

Artist's Comments

A client required that thumbnails be generated and placed equidistant from the edges of a square of a given size, depending on the aspect ratio of the image - that is to say that if the image was a landscape then it should be the same width of the square while being placed in the vertical middle. After checking any number of resources I couldn't find an appropriate script so I rolled my own. I'm pretty pleased with it and you're more than welcome to have it from here.

You can view the script as a PDF here.

If you make alterations, and more importantly improvements, please do let me know.

Take it easy.
[x]

Critiques


Thank you for your Critique

You are not logged in.

Devious Comments

love 0 0 joy 0 0 wow 0 0 mad 0 0 sad 0 0 fear 0 0 neutral 0 0

Comments


Well, overall, it's a pretty good script, but since you encouraged advanced critique, there are a few things you might want to change.

First, your script crashes if it encounters a non-JPEG file. I never understood why you used substr($file, -3, 3)=="php" instead of substr($file, -4)==".jpg".

Second, don't use scandir(), it's PHP 5 only. opendir, readdir, closedir works just as well.

Third, using $_GET isn't a really good idea unless the script is protected elsewhere, since someone could DoS your server by running that script repeatedly once they found it.

Fourth, you should sanitize your input; make sure size is positive, make sure color is a color, etc.

Fifth, why didn't you combine statements? if ($file == ".") continue; if ($file == "..") continue; can easily be shortened to if ($file=='.'||$file=='..') continue;, which in turn can be shortened to if (substr($file,0,1)=='.') continue, since any UNIX file that starts with . should not be touched (for instance, .HTACCESS).

Here's my rewritten version of it.

[link]

It's kind of sparse on comments, so if you don't understand something, feel free to ask.

The improvements are:

- faster, smaller
- transparent backgrounds
- function interface
- different naming scheme
- works for all images, not just JPEGs
- doesn't crash on non-PHP non-JPEG files
- doesn't crash on invalid image files
Consider creating a method which will resize any gif, jpg, or png image and utilizing that here - that will give your code more power, since it can handle multiple filetypes, and also make it more reusable.

--
Check out my Website Development Blog.
Cheers =genstones. I concentrated on jpegs as I'm working through the tutorials in .net.
Nice code, but you should really be filtering those $_GET calls for malicious code.

--
The DataGrid control is intended for viewing data, and not as a layout tool like an HTML table - Adobe
Very, very nice work. Good to see things like hexadecimal right shifts. My only comment is that `mkthumbdir` does not appear to return false, if `mkthumb` returns false. Unless I'm reading something wrong, `mkthumbdir` always returns true, and thus `mkthumbdir() or die('Error.';);` will never error?

--
camendesign.com - code is art
Thanks muchly, though the context for which is was written (a quick and dirty thing to generate thumbnails without having to wade through GIMP for each one) meant that it was run once then deleted.

Should I use it in anger then you are of course correct.

Site Map