Exemplo n.º 1
0
function makethumbnail($src_file, $newSize, $method)
{
    global $CONFIG;
    $content_type = array(IMAGETYPE_GIF => 'gif', IMAGETYPE_JPEG => 'jpeg', IMAGETYPE_PNG => 'png');
    // Checks that file exists and is readable
    if (!filesize($src_file) || !is_readable($src_file)) {
        header("Content-type: image/gif");
        fpassthru(fopen(READ_ERROR_ICON, 'rb'));
        exit;
    }
    // find the image size, no size => unknow type
    $imginfo = getimagesize($src_file);
    if ($imginfo == null) {
        header("Content-type: image/gif");
        fpassthru(fopen(UNKNOW_ICON, 'rb'));
        exit;
    }
    // GD can't handle gif images
    if ($imginfo[2] == IMAGETYPE_GIF && ($method == 'gd1' || $method == 'gd2') && !function_exists('imagecreatefromgif')) {
        header("Content-type: image/gif");
        fpassthru(fopen(GIF_ICON, 'rb'));
        exit;
    }
    // height/width
    $ratio = max(max($imginfo[0], $imginfo[1]) / $newSize, 1.0);
    $dest_info[0] = intval($imginfo[0] / $ratio);
    $dest_info[1] = intval($imginfo[1] / $ratio);
    $dest_info['quality'] = intval($CONFIG['jpeg_qual']);
    require_once 'includes/imaging/imaging.inc';
    if (!Graphic::show($src_file, $dest_info)) {
        return false;
    }
}