示例#1
0
                         } else {
                             $mode = @coalesce($p['m'], IMAGE_EDITOR_RESIZE_PROPORTIONAL);
                         }
                     }
                     $thumb_width = (int) @coalesce($params['w'], $params['h']);
                     $thumb_height = (int) @coalesce($params['h'], $params['w']);
                     $IE->resize($thumb_width, $thumb_height, $mode);
                     break;
             }
             if (isset($params['b']) && $params['b']) {
                 $IE->blurred((int) $params['b']);
             }
             if (isset($params['d']) && $params['d']) {
                 $IE->decreaseBrightness((int) $params['d']);
             }
             $IE->commit();
         }
         $file_name = $cache_name;
     }
 }
 $last_modified = filemtime($file_name);
 if (!empty($file_name) && !empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
     header('HTTP/1.0 304 Not Modified');
 } else {
     if (!empty($file_name)) {
         $size = getimagesize($file_name);
         header("Content-type: {$size['mime']}");
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $last_modified) . ' GMT');
         readfile($file_name);
     } else {
         throw new Exception('File not found');
示例#2
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());
    }
}