Ejemplo n.º 1
0
function MG_createDisplayImage($srcImage, $imageDisplay, $mimeExt, $mimeType, $aid, $dnc = 1)
{
    global $_CONF, $_TABLES, $_MG_CONF, $_SPECIAL_IMAGES_MIMETYPE;
    $imgsize = @getimagesize($srcImage);
    if ($imgsize == false && !in_array($mimeType, $_SPECIAL_IMAGES_MIMETYPE)) {
        return array(false, 'Unable to determine src image dimensions');
    }
    $imgwidth = $imgsize[0];
    $imgheight = $imgsize[1];
    $sql = "SELECT display_image_size " . "FROM {$_TABLES['mg_albums']} WHERE album_id = " . intval($aid);
    $result = DB_query($sql);
    $A = DB_fetchArray($result);
    list($dImageWidth, $dImageHeight) = MG_getImageSize($A['display_image_size']);
    if ($imgwidth == 0 || $imgheight == 0) {
        $imgwidth = $dImageWidth;
        $imgheight = $dImageHeight;
    }
    if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga') {
        $fp = @fopen($srcImage, 'rb');
        if ($fp == false) {
            $imgwidth = 0;
            $imgheight = 0;
        } else {
            $data = fread($fp, filesize($srcImage));
            fclose($fp);
            $imgwidth = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
            $imgheight = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
        }
    }
    $tmpImage = '';
    if (in_array($mimeType, $_SPECIAL_IMAGES_MIMETYPE)) {
        $tmpImage = $_MG_CONF['tmp_path'] . 'wip' . rand() . '.jpg';
        list($rc, $msg) = MG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
        if ($rc == false) {
            COM_errorLog("MG_createDisplayImage: Error converting uploaded image to jpeg format.");
            @unlink($srcImage);
            return array(false, $msg);
        }
    }
    if ($tmpImage != '') {
        list($rc, $msg) = MG_resizeImage($tmpImage, $imageDisplay, $dImageHeight, $dImageWidth, '', 0, $_MG_CONF['jpg_quality']);
        //      list($rc,$msg) = MG_resizeImage($tmpImage, $imageDisplay, $imgheight,    $imgwidth,    '', 0, $_MG_CONF['jpg_quality']);
    } else {
        list($rc, $msg) = MG_resizeImage($srcImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0, $_MG_CONF['jpg_quality']);
        //      list($rc,$msg) = MG_resizeImage($srcImage, $imageDisplay, $imgheight,    $imgwidth,    $mimeType, 0, $_MG_CONF['jpg_quality']);
    }
    if ($rc == false) {
        @unlink($srcImage);
        @unlink($tmpImage);
        return array(false, $msg);
    }
    if ($tmpImage != '') {
        @unlink($tmpImage);
    }
    if ($_MG_CONF['discard_original'] != 1) {
        // discard original image file
        list($rc, $msg) = MG_processOriginal($srcImage, $mimeExt, $mimeType, $aid, $dnc);
        if ($rc == false) {
            @unlink($srcImage);
            @unlink($imageDisplay);
            @unlink($tmpImage);
            return array(false, $msg);
        }
    }
    return array(true, '');
}
Ejemplo n.º 2
0
function MG_convertImage($srcImage, $imageThumb, $imageDisplay, $mimeExt, $mimeType, $aid, $baseFilename, $dnc)
{
    global $_CONF, $_MG_CONF, $MG_albums;
    $makeSquare = 0;
    if ($_MG_CONF['verbose']) {
        COM_errorLog("MG Upload: Entering MG_convertImage()");
    }
    if ($_MG_CONF['verbose']) {
        COM_errorLog("MG Upload: Creating thumbnail image");
    }
    $imgsize = @getimagesize("{$srcImage}");
    if ($imgsize == false && $mimeType != 'image/x-targa' && $mimeType != 'image/tga' && $mimeType != 'image/photoshop' && $mimeType != 'image/x-photoshop' && $mimeType != 'image/psd' && $mimeType != 'application/photoshop' && $mimeType != 'application/psd') {
        return array(false, 'Unable to determine src image dimensions');
    }
    $imgwidth = $imgsize[0];
    $imgheight = $imgsize[1];
    // --
    // Create the thumbnail image
    // --
    if ($MG_albums[$aid]->tn_size == 3 || $MG_albums[$aid]->tn_size == 4) {
        $tnHeight = $MG_albums[$aid]->tnHeight;
        $tnWidth = $MG_albums[$aid]->tnWidth;
        if ($tnHeight == 0) {
            $tnHeight = 200;
        }
        if ($tnWidth == 0) {
            $tnWidth = 200;
        }
        if ($MG_albums[$aid]->tn_size == 4) {
            $makeSquare = 1;
        }
    } else {
        if ($_MG_CONF['thumbnail_actual_size'] == 1) {
            switch ($MG_albums[$aid]->tn_size) {
                case 0:
                    $tnHeight = 100;
                    $tnWidth = 100;
                    break;
                case 1:
                    $tnHeight = 150;
                    $tnWidth = 150;
                    break;
                default:
                    $tnHeight = 200;
                    $tnWidth = 200;
                    break;
            }
        } else {
            $tnHeight = 200;
            $tnWidth = 200;
        }
    }
    $tmpImage = '';
    if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd' || $mimeType == 'image/tiff') {
        $tmpImage = $_MG_CONF['tmp_path'] . '/wip' . rand() . '.jpg';
        list($rc, $msg) = IMG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
        if ($rc == false) {
            COM_errorLog("MG_convertImage: Error converting uploaded image to jpeg format.");
            @unlink($srcImage);
            return array(false, $msg);
        }
        if ($makeSquare == 1) {
            list($rc, $msg) = IMG_squareThumbnail($tmpImage, $imageThumb, $tnWidth, '', 0);
        } else {
            list($rc, $msg) = IMG_resizeImage($tmpImage, $imageThumb, $tnHeight, $tnWidth, '', 0);
        }
    } else {
        if ($makeSquare == 1) {
            list($rc, $msg) = IMG_squareThumbnail($srcImage, $imageThumb, $tnWidth, $mimeType, 0);
        } else {
            list($rc, $msg) = IMG_resizeImage($srcImage, $imageThumb, $tnHeight, $tnWidth, $mimeType, 0);
        }
    }
    if ($rc == false) {
        COM_errorLog("MG_convertImage: Error resizing uploaded image to thumbnail size.");
        @unlink($srcImage);
        return array(false, $msg);
    }
    // --
    // Create Display Image
    // --
    switch ($MG_albums[$aid]->display_image_size) {
        case 0:
            $dImageWidth = 500;
            $dImageHeight = 375;
            break;
        case 1:
            $dImageWidth = 600;
            $dImageHeight = 450;
            break;
        case 2:
            $dImageWidth = 620;
            $dImageHeight = 465;
            break;
        case 3:
            $dImageWidth = 720;
            $dImageHeight = 540;
            break;
        case 4:
            $dImageWidth = 800;
            $dImageHeight = 600;
            break;
        case 5:
            $dImageWidth = 912;
            $dImageHeight = 684;
            break;
        case 6:
            $dImageWidth = 1024;
            $dImageHeight = 768;
            break;
        case 7:
            $dImageWidth = 1152;
            $dImageHeight = 804;
            break;
        case 8:
            $dImageWidth = 1280;
            $dImageHeight = 1024;
            break;
        case 9:
            $dImageWidth = $_MG_CONF['custom_image_width'];
            $dImageHeight = $_MG_CONF['custom_image_height'];
            break;
        default:
            $dImageWidth = 620;
            $dImageHeight = 465;
            break;
    }
    if ($imgwidth == 0 || $imgheight == 0) {
        $imgwidth = $dImageWidth;
        $imgheight = $dImageHeight;
    }
    if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga') {
        $fp = fopen($srcImage, 'rb');
        $data = fread($fp, filesize($srcImage));
        fclose($fp);
        $imgwidth = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
        $imgheight = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
    }
    if ($tmpImage != '') {
        list($rc, $msg) = IMG_resizeImage($tmpImage, $imageDisplay, $dImageHeight, $dImageWidth, '', 0);
    } else {
        list($rc, $msg) = IMG_resizeImage($srcImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0);
    }
    if ($rc == false) {
        @unlink($srcImage);
        @unlink($imageThumb);
        @unlink($tmpImage);
        return array(false, $msg);
    }
    if ($tmpImage != '') {
        @unlink($tmpImage);
    }
    if ($_MG_CONF['discard_original'] != 1) {
        list($rc, $msg) = MG_processOriginal($srcImage, $mimeExt, $mimeType, $aid, $baseFilename, $dnc);
        if ($rc == false) {
            @unlink($srcImage);
            @unlink($imageThumb);
            @unlink($imageDisplay);
            @unlink($tmpImage);
            return array(false, $msg);
        }
    }
    @chmod($imageThumb, 0644);
    @chmod($imageDisplay, 0644);
    return array(true, '');
}