示例#1
0
 } else {
     if (file_exists($source) && !empty($params)) {
         $cache_path = IMG_CACHE_PATH . dirname($_REQUEST['__path']);
         if (!file_exists($cache_path)) {
             mkdir(IMG_CACHE_PATH . dirname($_REQUEST['__path']), 0777, true);
         }
         if (!file_exists($cache_path)) {
             throw new Exception('Cache path was not created');
         }
         $cache_name = $cache_path . DIRECTORY_SEPARATOR . basename($_REQUEST['__path']);
         if (!file_exists(IMG_CACHE_PATH)) {
             mkdir(IMG_CACHE_PATH, 0777, true);
         }
         if (!file_exists($cache_name)) {
             require BASE_PATH . '/lib/Cpeople/ImageEditor.class.php';
             $IE = new ImageEditorGD();
             $IE->setSource($source)->setTarget($cache_name);
             $size = @coalesce($params['s'], $params['w']);
             if (isset($params['e']) && (int) $params['e'] > 0 && (int) $params['e'] < 500) {
                 $IE->cutEdgesByPercentage($v, $v, $v, $v);
             }
             switch (@$params['t']) {
                 case 'square':
                     $IE->square($size);
                     break;
                 case 'square_put':
                     $IE->putIntoSquare($size);
                     break;
                 case 'put':
                     if (empty($params['w'])) {
                         throw new Exception('Width is not set for method PUT');
示例#2
0
 } else {
     if (file_exists($source) && !empty($params)) {
         $cache_path = IMG_CACHE_PATH . dirname($_REQUEST['__path']);
         if (!file_exists($cache_path)) {
             mkdir(IMG_CACHE_PATH . dirname($_REQUEST['__path']), 0777, true);
         }
         if (!file_exists($cache_path)) {
             throw new Exception('Cache path was not created');
         }
         $cache_name = $cache_path . DIRECTORY_SEPARATOR . basename($_REQUEST['__path']);
         if (!file_exists(IMG_CACHE_PATH)) {
             mkdir(IMG_CACHE_PATH, 0777, true);
         }
         if (!file_exists($cache_name)) {
             require BASE_PATH . '/lib/BitrixHelperLib/ImageEditor.class.php';
             $IE = new ImageEditorGD();
             $IE->setSource($source)->setTarget($cache_name);
             $size = @coalesce($params['s'], $params['w']);
             if (isset($params['e']) && (int) $params['e'] > 0 && (int) $params['e'] < 500) {
                 $IE->cutEdgesByPercentage($v, $v, $v, $v);
             }
             switch (@$params['t']) {
                 case 'square':
                     $IE->square($size);
                     break;
                 case 'square_put':
                     $IE->putIntoSquare($size);
                     break;
                 case 'put':
                     if (empty($params['w'])) {
                         throw new Exception('Width is not set for method PUT');
示例#3
0
function cp_generate_thumb($url, $resizedUrl, $options)
{
    try {
        $sourcePath = BASE_PATH . $url;
        $targetPath = BASE_PATH . preg_replace('#(\\?.*)#', '', $resizedUrl);
        $targetDir = dirname($targetPath);
        if (file_exists($targetPath)) {
            throw new Exception('Already exists');
        }
        if (!file_exists($sourcePath)) {
            throw new Exception('Source not found');
        }
        if (!file_exists($targetDir)) {
            mkdir($targetDir, 0777, true);
        }
        if (!file_exists($targetDir)) {
            throw new Exception('Could not create cache dir');
        }
        if (!class_exists('ImageEditorGD')) {
            require_once BASE_PATH . '/lib/BitrixHelperLib/ImageEditor.class.php';
        }
        $IE = new ImageEditorGD();
        $IE->setSource($sourcePath)->setTarget($targetPath);
        $size = @coalesce($options['size'], $options['width']);
        switch (@$options['type']) {
            case 'square':
                $IE->square($size);
                break;
            case 'square_put':
                $IE->putIntoSquare($size);
                break;
            case 'put':
                if (empty($options['width'])) {
                    throw new Exception('Width is not set for method PUT');
                }
                if (empty($options['height'])) {
                    throw new Exception('Height is not set for method PUT');
                }
                $IE->putIntoSize($options['width'], $options['height']);
                break;
            case 'put_out':
                if (empty($options['width'])) {
                    throw new Exception('Width is not set for method PUT');
                }
                if (empty($options['height'])) {
                    throw new Exception('Height is not set for method PUT');
                }
                $IE->cutIntoSize($options['width'], $options['height']);
                break;
            default:
                if (empty($options['width'])) {
                    $mode = IMAGE_EDITOR_RESIZE_HEIGHT;
                } else {
                    if (empty($options['height'])) {
                        $mode = IMAGE_EDITOR_RESIZE_WIDTH;
                    } else {
                        $mode = @coalesce($options['mode'], IMAGE_EDITOR_RESIZE_PROPORTIONAL);
                    }
                }
                $thumb_width = (int) @coalesce($options['width'], $options['height']);
                $thumb_height = (int) @coalesce($options['height'], $options['width']);
                $IE->resize($thumb_width, $thumb_height, $mode);
                break;
        }
        $IE->commit();
    } catch (Exception $e) {
        //        dv( 'cp_generate_thumb: ' . $e->getMessage());
    }
}