Example #1
0
/**
 * Prepare image file (Resize, Rotate and etc.)
 *
 * @param object File
 * @param string mimetype
 */
function prepare_uploaded_image($File, $mimetype)
{
    global $Settings;
    $thumb_width = $Settings->get('fm_resize_width');
    $thumb_height = $Settings->get('fm_resize_height');
    $thumb_quality = $Settings->get('fm_resize_quality');
    $do_resize = false;
    if ($Settings->get('fm_resize_enable') && $thumb_width > 0 && $thumb_height > 0) {
        // Image resizing is enabled
        list($image_width, $image_height) = explode('x', $File->get_image_size());
        if ($image_width > $thumb_width || $image_height > $thumb_height) {
            // This image should be resized
            $do_resize = true;
        }
    }
    load_funcs('files/model/_image.funcs.php');
    $resized_imh = null;
    if ($do_resize) {
        // Resize image
        list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
        if (empty($err)) {
            list($err, $resized_imh) = generate_thumb($src_imh, 'fit', $thumb_width, $thumb_height);
        }
    }
    if (!empty($err)) {
        // Error exists, Exit here
        return;
    }
    if ($mimetype == 'image/jpeg') {
        // JPEG, do autorotate if EXIF Orientation tag is defined
        $save_image = !$do_resize;
        // If image was be resized, we should save file only in the end of this function
        exif_orientation($File->get_full_path(), $resized_imh, $save_image);
    }
    if (!$resized_imh) {
        // Image resource is incorrect
        return;
    }
    if ($do_resize && empty($err)) {
        // Save resized image ( and also rotated image if this operation was done )
        save_image($resized_imh, $File->get_full_path(), $mimetype, $thumb_quality);
    }
}
Example #2
0
/**
 * Prepare image file (Resize, Rotate and etc.)
 *
 * @param object File
 * @param string mimetype
 */
function prepare_uploaded_image($File, $mimetype)
{
    global $Settings, $Messages;
    $thumb_width = $Settings->get('fm_resize_width');
    $thumb_height = $Settings->get('fm_resize_height');
    $thumb_quality = $Settings->get('fm_resize_quality');
    $do_resize = false;
    if ($Settings->get('fm_resize_enable') && $thumb_width > 0 && $thumb_height > 0) {
        // Image resizing is enabled
        list($image_width, $image_height) = explode('x', $File->get_image_size());
        if ($image_width > $thumb_width || $image_height > $thumb_height) {
            // This image should be resized
            $do_resize = true;
        }
    }
    load_funcs('files/model/_image.funcs.php');
    $resized_imh = null;
    if ($do_resize) {
        // Resize image
        list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
        if (empty($err)) {
            list($err, $resized_imh) = generate_thumb($src_imh, 'fit', $thumb_width, $thumb_height);
        }
        if (empty($err)) {
            // Image was rezised successfully
            $Messages->add(sprintf(T_('%s was resized to %dx%d pixels.'), '<b>' . $File->get('name') . '</b>', imagesx($resized_imh), imagesy($resized_imh)), 'success');
        } else {
            // Image was not rezised
            $Messages->add(sprintf(T_('%s could not be resized to target resolution of %dx%d pixels.'), '<b>' . $File->get('name') . '</b>', $thumb_width, $thumb_height), 'error');
            // Error exists, exit here
            return;
        }
    }
    if ($mimetype == 'image/jpeg') {
        // JPEG, do autorotate if EXIF Orientation tag is defined
        $save_image = !$do_resize;
        // If image was be resized, we should save file only in the end of this function
        exif_orientation($File->get_full_path(), $resized_imh, $save_image);
    }
    if (!$resized_imh) {
        // Image resource is incorrect
        return;
    }
    if ($do_resize && empty($err)) {
        // Save resized image ( and also rotated image if this operation was done )
        save_image($resized_imh, $File->get_full_path(), $mimetype, $thumb_quality);
    }
}