New deals posted everyday, starting Black Friday and running through the holiday season! No hassles, no lines - just awesome savings on art, deviantWEAR, Premium Memberships and more!

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. 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.
How's mkthumb()?
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.'
-- camendesign.comcode is art |
Details
March 19, 2007
1.8 MB 1.8 MB 1275×2891 StatisticsShare
Link
Embed
Thumb
|
Critiques
Thank you for your Critique
You are not logged in.