Пример #1
1
 protected function _resize_animated_gif($max_w, $max_h, $crop = true)
 {
     include_once 'gdenhancer/GDEnhancer.php';
     //path of your GDEnhancer.php
     $image = new GDEnhancer($this->file);
     $image->backgroundResize($max_w, $max_h, 'shrink');
     //option shrink
     return $image->save();
 }
Пример #2
0
function resize($filename, $resize_width, $resize_height, $texttype = false, $filename_src)
{
    global $config, $_POST, $error;
    $ext = strtolower(strrchr(basename($filename), "."));
    // Получаем формат уменьшаемого изображения
    $info = getimagesize($filename);
    // Возвращает ширину и высоту картинки
    $width = $info['0'];
    $height = $info['1'];
    if ($resize_height > $height or $resize_width > $width) {
        $error[] = "Нельзя уменьшать изображение в большую сторону";
    } else {
        list($resize_width, $resize_height) = get_resize_proportions($height, $width, $resize_height, $resize_width);
        $type = '';
        if (!$info['mime']) {
            switch ($ext) {
                case '.gif':
                    $type = 'gif';
                    break;
                case '.png':
                    $type = 'png';
                    break;
                case '.jpg':
                    $type = 'jpg';
                    break;
                case '.jpeg':
                    $type = 'jpg';
                    break;
                    //case '.bmp' : $type='bmp'; break; - здесь уже не должно быть BMP
            }
        } else {
            switch ($info['mime']) {
                case 'image/gif':
                    $type = 'gif';
                    break;
                case 'image/pjpeg':
                    $type = 'jpg';
                    break;
                case 'image/jpeg':
                    $type = 'jpg';
                    break;
                case 'image/x-png':
                    $type = 'png';
                    break;
                case 'image/png':
                    $type = 'png';
                    break;
                    //case 'image/bmp'  : $type='bmp'; break;  - здесь уже не должно быть BMP
                    //case 'image/x-ms-bmp' : $type='bmp'; break;
            }
        }
        if ($type != '') {
            include_once 'gdenhancer/GDEnhancer.php';
            //path of GDEnhancer.php
            $image = new GDEnhancer($filename);
            $image->backgroundResize($resize_width, $resize_height, 'shrink');
            //option shrink
            //текст на превью
            if (isset($texttype) and $texttype and $texttype != "nothing") {
                $filesize = formatfilesize(filesize($filename));
                if ($texttype == 'dimensions') {
                    $text = $width . 'x' . $height . '(' . $filesize . ')';
                } else {
                    $text = $_POST['text'];
                }
                $DARKNESS = 70;
                //FIXME: вынести в конфиг!
                //"полупрозрачный" слой подложки под текст
                $imglayer = imagecreatetruecolor($width, 15);
                imagesavealpha($imglayer, true);
                $color = imagecolorallocatealpha($imglayer, 0, 0, 0, $DARKNESS);
                imagefill($imglayer, 0, 0, $color);
                ob_start();
                imagepng($imglayer);
                $image_data = ob_get_contents();
                ob_end_clean();
                imagedestroy($imglayer);
                $image->layerImage($image_data);
                $image->layerMove(0, "top", 0, $resize_height - 15);
                $save = $image->save();
                unset($image);
                //сам текст
                $image = new GDEnhancer($save['contents']);
                $image->layerText($text, $config['site_dir'] . "/K1FS.ttf", '10', '#FFFFFF', 0, 1);
                $image->layerMove(0, "top", 2, $resize_height - 14);
            }
            $save = $image->save();
            file_put_contents($filename, $save['contents']);
            unset($image);
        }
    }
    //else resize_height>height
}
Пример #3
0
 private function addImage($old_path, $new_path, $image_path, $position)
 {
     if (!isset($this->database, $old_path, $new_path, $image_path, $position)) {
         return 'Missing parameters';
     }
     $image = new GDEnhancer($old_path);
     $image->layerImage($image_path);
     $image->layerMove(0, $position['align'], $position['x'], $position['y']);
     $save = $image->save();
     file_put_contents($new_path, $save['contents']);
     return true;
 }