CORRECT_PERMISSIONS, 'resizeUp' => $SCALE_UP, 'jpegQuality' => QUALITY); try { $thumb = PhpThumbFactory::create(($file_level=='master'?MASTER_DIR.'/'.$master_dir_clean.'/'.$file:$file), $options); } catch (Exception $e) { echo 'Thumbnail engine error.'; exit; } list($src_width, $src_height, $src_type, $src_attr) = getimagesize($file_level=='master'?MASTER_DIR.'/'.$master_dir_clean.'/'.$file:$file); if ($directive_parts_count<2){ echo 'Missing parameters.'; exit; } $method = $directive_parts[0]; if ($method == 'w' && $directive_parts_count==2){ // RESIZE BY WIDTH $dest_width = (int)$directive_parts[1]; $thumb->resize($dest_width, 0); } elseif ($method == 'h' && $directive_parts_count==2) { // RESIZE BY HEIGHT $dest_height = (int)$directive_parts[1]; $thumb->resize(0, $dest_height); } elseif ($method == 'f') { // RESIZE TO FIT BOX $dest_width = (int)$directive_parts[1]; $dest_height = (int)$directive_parts[2]; if (!$dest_height) { $dest_height = $dest_width; } $thumb->resize($dest_width, $dest_height); } elseif ($method == 'c') { // RESIZE AND CROP if ($directive_parts_count==2) { $dest_width = $dest_height = (int)$directive_parts[1]; } elseif ($directive_parts_count==3) { $dest_width = (int)$directive_parts[1]; if (in_array($directive_parts[2], $positions)){ $dest_height = $dest_width; $dest_position = $directive_parts[2]; } else { $dest_height = (int)$directive_parts[2]; $dest_position = 'cm'; } } elseif ($directive_parts_count==4) { $dest_width = (int)$directive_parts[1]; $dest_height = (int)$directive_parts[2]; if (!$dest_height) { $dest_height = $dest_width; } if (in_array($directive_parts[3], $positions)){ $dest_position = $directive_parts[3]; } else { $dest_position = 'cm'; } } if ($dest_position == 'cm') { $thumb->adaptiveResize($dest_width, $dest_height); } else { $location_x = $dest_position[0]; $location_y = $dest_position[1]; if($src_width >= $src_height) { $src_w = floor(($src_height * $dest_width) / $dest_height); if ($src_w > $src_width) { $src_h = floor(($src_width * $dest_height) / $dest_width); if ($location_y == "m") { $src_x = 0; $src_y = floor(($src_height - $src_h)/2); } elseif ($location_y == "t") { $src_x = 0; $src_y = 0; } elseif ($location_y == "b") { $src_x = 0; $src_y = $src_height - $src_h; } $thumb->crop($src_x, $src_y, $src_width, $src_h); } else { if ($location_x == "c") { $src_x = floor(($src_width - $src_w)/2); $src_y = 0; } elseif ($location_x == "l") { $src_x = 0; $src_y = 0; } elseif ($location_x == "r") { $src_x = $src_width - $src_w; $src_y = 0; } $thumb->crop($src_x, $src_y, $src_w, $src_height); } } else { $src_h = floor(($src_width * $dest_height) / $dest_width); if ($src_h > $src_height) { $src_w = ceil(($src_height * $dest_width) / $dest_height); if ($location_x == "c") { $src_y = 0; $src_x = floor(($src_width - $src_w)/2); } elseif ($location_x == "l") { $src_x = 0; $src_y = 0; } elseif ($location_x == "r") { $src_y = 0; $src_x = $src_width - $src_w; } $thumb->crop($src_x, $src_y, $src_w, $src_height); } else { if ($location_y == "m") { $src_y = floor(($src_height - $src_h)/2); $src_x = 0; } elseif ($location_y == "t") { $src_y = 0; $src_x = 0; } elseif ($location_y == "b") { $src_y = $src_height - $src_h; $src_x = 0; } $thumb->crop($src_x, $src_y, $src_width, $src_h); } } if ($dest_width > $dest_height) { $thumb->resize($dest_width, 0); } else { $thumb->resize(0, $dest_height); } } } else { echo 'Wrong parameters.'; exit; } ob_clean(); // added ob_clean to fix kourdisto issue $thumb->show(); $thumb->save($dir.'/'.$file); ?>