Пример #1
0
/**
 * Execute this function on page_not_found.
 * If the request is for an image file,
 * resize the image.
 */
function image_resize_try_resizing()
{
    // Require that visitor be logged in and has
    // permission to create files
    if (!AuthUser::isLoggedIn()) {
        AuthUser::load();
    }
    if (!AuthUser::hasPermission('administrator,developer,editor')) {
        return false;
    }
    // Check that gd library is available
    if (!ImageResize::gd_available()) {
        return false;
    }
    if (preg_match('#\\.(jpe?g|gif|png|wbmp)$#i', CURRENT_URI)) {
        // If requested file appears to be an accepted format, create the new image
        if (image_resize_scale(CURRENT_URI) && !DEBUG) {
            // If Frog isn't debugging, it writes to a file; redirect to it
            header('Location: ' . URL_PUBLIC . "/" . CURRENT_URI);
            // Exit here to prevent a page not found message
            exit;
        }
    }
}
 private static function do_resize_to_max_side($src_fn, $resized_fn, $max_x, $max_y, $resize_type = RESIZE_CROP)
 {
     $convert = ImageResize::find_magick();
     $magick_attempted = FALSE;
     if ($convert && !ImageResize::$skip_magick) {
         // try to do it with imagemagick
         $magick_attempted = TRUE;
         try {
             return ImageResize::magick_resize_image($convert, $src_fn, $resized_fn, $max_x, $max_y, $resize_type);
         } catch (CNException $magick_exc) {
             Logger::log("ImageMagick failed to resize {$src_fn}; trying GD");
         }
     }
     if (ImageResize::gd_available() && !ImageResize::$skip_gd) {
         // we have gd installed
         return ImageResize::gd_resize_image($src_fn, $resized_fn, $max_x, $max_y, $resize_type);
     }
     if ($magick_attempted) {
         throw $magick_exc;
     }
     throw new CNException(MISSING_DEPENDENCY, "need to have either gd or imagemagick installed to resize images");
 }
 public function documentation()
 {
     $this->display('image_resize/views/documentation', array('gd_status' => ImageResize::gd_available(), 'mod_rewrite_status' => USE_MOD_REWRITE));
 }