+function mkthumb_gd($source, $target, $width, $height)
+{
+ $data = imagecreatefromstring(file_get_contents($source));
+ if (!$data) throw new Exception("error reading $source");
+ $orgwidth = imagesx($data);
+ $orgheight = imagesy($data);
+ $width = min($width, $orgwidth * $height / $orgheight);
+ $gd = imagecreatetruecolor($width, $height);
+ //TODO: trim
+ imagecopyresampled($gd, $data, 0, 0, 0, 0,
+ $width, $height, $orgwidth, $orgheight);
+ imagejpeg($gd, $target, 90);
+}
+
+function mkthumb_exec($source, $target, $width, $height)
+{
+ if (!function_exists('popen')) {
+ throw new Exception("exec disallowed on this server", 501);
+ }