Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
File
clean_filename($filename)
duplicate_name($name, etc)
fetch_dirlist($path='', $exts='')
file_ext($file)
file_label($file, $label)
fsize($x)
resize_image($image, $sizes)
7
found
auth
Name:
Category: File
Body:
// Uses image class @ http://mech.cx/tools/functions.php?id=104 and styledText function // Long overdue update received on [2010-12-23 14:01:55] (force resize bool, paths) //_____________________________________________ // resize_image($image, $sizes, $force=false) / function resize_image($image, $sizes, $force=false) { global $messages; // require_once 'class/my_image.class.php'; $I = new Image($image); if ($I->data) { foreach($sizes as $label => $size) { if (! $label) $label = ''; // numeric 0 becomes empty string. It makes sense. if (strpos($label, '/')!==false) { // Since '/' is illegal in a filename on most filesystems, we'll interpret this as a // path, instead. And add [another] slash if needed. // [2010-12-19 13:05:48] Also, we'll strip the path info from the current image, if any $newname = $label .(substr($label, -1)!='/' ? '/':''). basename($image); }else{ $newname = file_label($image, $label); // foo.jpg + '_thumb' = foo_thumb.jpg } // now we attempt some hackery to only resize it if needed (unless $force == true) $resize = false; if (! $force) { $x = $I->getxy('x'); $new_size = $I->calc_sizes($x, $I->getxy('y'), $size); if (! is_array($new_size)) { continue; } $new_x = $new_size[0]; if ($new_x < $x) $resize = true; } if ($resize or $force) { $J = clone $I; $J->scale_image($size); if (! $J->save($newname)) { $messages[] = styledText('Fouten bij resize_image(): '. join('<br>', $I->getErrors()), 'red'); } $J->destroy(); }else{ $messages[] = styledText("Skipped resizing $label => ". json_encode($size) .", image too small<br>\n", '#f80'); } } $I->destroy(); }else{ $messages[] = styledText("Fout bij het schalen van afbeelding.", 'red'); } }
Footer