Exemple #1
1
 /**
  * {@inheritdoc}
  */
 public function offsetSet($offset, $image)
 {
     if (!$image instanceof Image) {
         throw new InvalidArgumentException('Only an Imagick Image can be used as layer');
     }
     if (null === $offset) {
         $offset = count($this) - 1;
     } else {
         if (!is_int($offset)) {
             throw new InvalidArgumentException('Invalid offset for layer, it must be an integer');
         }
         if (count($this) < $offset || 0 > $offset) {
             throw new OutOfBoundsException(sprintf('Invalid offset for layer, it must be a value between 0 and %d, %d given', count($this), $offset));
         }
         if (isset($this[$offset])) {
             unset($this[$offset]);
             $offset = $offset - 1;
         }
     }
     $frame = $image->getImagick();
     try {
         if (count($this) > 0) {
             $this->resource->setIteratorIndex($offset);
         }
         $this->resource->addImage($frame);
     } catch (\ImagickException $e) {
         throw new RuntimeException('Unable to set the layer', $e->getCode(), $e);
     }
     $this->layers = array();
 }
Exemple #2
0
 /**
  * Turns object into one frame Imagick object
  * by removing all frames except first
  *
  * @param  Imagick $object
  * @return Imagick
  */
 private function removeAnimation(\Imagick $object)
 {
     $imagick = new \Imagick();
     foreach ($object as $frame) {
         $imagick->addImage($frame->getImage());
         break;
     }
     $object->destroy();
     return $imagick;
 }
 public function createThumb()
 {
     //        $imagick = new \Imagick();
     $output = new \Imagick();
     $imagick->setIteratorIndex(1);
     $output->addImage($imagick->getimage());
     //        $imagick->setIteratorIndex(2);
     //        $output->addImage($imagick->getimage());
     $merged = @$output->flattenimages();
     $merged->setImageFormat('jpg');
     $merged->writeImage('test.jpg');
 }
Exemple #4
0
 /**
  * Generate the animated gif
  *
  * @return string binary image data
  */
 private function createAnimation($images)
 {
     $animation = new \Imagick();
     $animation->setFormat('gif');
     foreach ($images as $image) {
         $frame = new \Imagick();
         $frame->readImageBlob($image);
         $animation->addImage($frame);
         $animation->setImageDelay(50);
     }
     return $animation->getImagesBlob();
 }
 /**
  * Processes an image.
  *
  * @param \Imagick $inputImage
  * @return \Imagick The processed image.
  */
 public function processImage(\Imagick $inputImage)
 {
     $totalFrames = 0;
     $uniqueFrameDelays = [];
     // If the image isn't animated, we don't have to do anything.
     if ($inputImage->getIteratorIndex() < 2) {
         return $inputImage;
     }
     $imageCopy = $inputImage->coalesceImages();
     // Count frames, and build a set of unique frame delay amounts.
     /** @var \Imagick $item */
     foreach ($imageCopy as $item) {
         $totalFrames++;
         $delay = $item->getImageDelay();
         if (!isset($uniqueFrameDelays[$delay])) {
             $uniqueFrameDelays[$delay] = 0;
         }
         $uniqueFrameDelays[$delay]++;
     }
     // If all the frames are the same length, we don't need to do anything.
     if (1 === count($uniqueFrameDelays)) {
         return $inputImage;
     }
     // To re-time the animation, we'll need to find the least common
     // multiple of all the frame delays.
     $frameDelays = array_keys($uniqueFrameDelays);
     $newDelay = max(min($frameDelays), gcf_array($frameDelays));
     $inputImage = $inputImage->coalesceImages();
     $outputImage = new \Imagick();
     var_dump(["Input delay", $inputImage->getImageDelay()]);
     /** @var \Imagick $frame */
     foreach ($inputImage as $frame) {
         $outputFrame = clone $frame->getImage();
         $frameCount = floor($outputFrame->getImageDelay() / $newDelay);
         $outputFrame->setImageDelay($newDelay);
         for ($i = 0; $i < $frameCount; $i++) {
             $outputImage->addImage($outputFrame);
         }
     }
     //        $outputImage = $outputImage->deconstructImages();
     $outputImage->setImageFormat('gif');
     foreach ($outputImage as $frame) {
         var_dump($frame->getImageDelay());
     }
     var_dump($inputImage->getImageLength());
     var_dump($outputImage->getImageLength());
     $outputImage->writeImages("output.gif", true);
     return $outputImage;
 }
Exemple #6
0
 public function example2()
 {
     $graph = new \Imagick();
     $graph->newPseudoImage(256, 256, "xc:pink");
     $imagick = new \Imagick();
     $imagick->newPseudoImage(256, 256, 'gradient:black-white');
     $arguments = array(9, -90);
     $imagick->functionImage(\Imagick::FUNCTION_SINUSOID, $arguments);
     $graph->addImage($imagick);
     $fx = 'colorInt=int(256 * v.p{0,j}.lightness); pos=int(i); (int(pos) >= colorInt && int(pos) <= colorInt)';
     $fxImage = $graph->fxImage($fx);
     //        fxAnalyzeImage($imagick);
     header("Content-Type: image/png");
     $fxImage->setimageformat('png');
     echo $fxImage->getImageBlob();
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function animate(array $frames, $delay = 20)
 {
     $gif = new \Imagick();
     $gif->setFormat('gif');
     foreach ($frames as $im) {
         if ($im instanceof Imanee) {
             $frame = $im->getResource()->getResource();
         } else {
             $frame = new \Imagick($im);
         }
         $frame->setImageDelay($delay);
         $gif->addImage($frame);
     }
     $imagickResource = new ImagickResource();
     $imagickResource->setResource($gif);
     $imanee = new Imanee();
     $imanee->setResource($imagickResource);
     $imanee->setFormat('gif');
     return $imanee;
 }
<?php

$combined = null;
$images = ['../../../imagick/images/Biter_500.jpg', '../../../imagick/images/Source1.png'];
foreach ($images as $image) {
    /** @var $combined \Imagick */
    if ($combined == null) {
        $combined = new Imagick(realpath($image));
    } else {
        $card = new Imagick(realpath($image));
        //get single card
        $combined->addImage($card);
    }
}
$combined->setImageFormat("pdf");
$combined->writeImages('./card.pdf', true);
Exemple #9
0
 /**
  * Resamples an image to a new copy
  *
  * @param Imagick $dst_image
  * @param Imagick $src_image
  * @param int $dst_x
  * @param int $dst_y
  * @param int $src_x
  * @param int $src_y
  * @param int $dst_w
  * @param int $dst_h
  * @param int $src_w
  * @param int $src_h
  * @return bool
  */
 function zp_resampleImage($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     foreach ($src_image->getImageProfiles() as $name => $profile) {
         $dst_image->profileImage($name, $profile);
     }
     $result = true;
     $src_image = $src_image->coalesceImages();
     foreach ($src_image as $frame) {
         $frame->cropImage($src_w, $src_h, $src_x, $src_y);
         $frame->setImagePage(0, 0, 0, 0);
     }
     $src_image = $src_image->coalesceImages();
     foreach ($src_image as $frame) {
         $frame->resizeImage($dst_w, $dst_h, Imagick::FILTER_LANCZOS, 1);
         $dst_image->setImageDelay($frame->getImageDelay());
         $result &= $dst_image->compositeImage($frame, Imagick::COMPOSITE_OVER, $dst_x, $dst_y);
         if ($dst_image->getNumberImages() < $src_image->getNumberImages()) {
             $result &= $dst_image->addImage(zp_createImage($dst_image->getImageWidth(), $dst_image->getImageHeight()));
         }
         if (!$result) {
             break;
         }
     }
     return $result;
 }
Exemple #10
0
        if (!in_array($tileNumber, $frames)) {
            continue;
        }
        $path = $dir . '/' . $filename;
        $originalImage = new Imagick($path);
        $resultImage->addimage($originalImage);
        $originalImage->clear();
        $originalImage->destroy();
    }
    $resultImages[$direction] = $resultImage;
}
$image = new Imagick();
foreach ($resultImages as $resultImage) {
    /** @var Imagick $resultImage */
    $resultImage->resetIterator();
    $sprite = $resultImage->appendImages(false);
    $resultImage->clear();
    $resultImage->destroy();
    $sprite->setImageFormat('png');
    $image->addImage($sprite);
    $sprites[] = $sprite;
}
$image->resetIterator();
$response = $image->appendImages(true);
$image->clear();
$image->destroy();
$response->setImageFormat('png');
$response->writeImage(__DIR__ . '/' . $argv[1] . '.png');
$response->clear();
$response->destroy();
echo 'All files were processed', PHP_EOL;
 /**
  * Put image to square
  *
  * @param  string $path image file
  * @param  int $width square width
  * @param  int $height square height
  * @param int|string $align reserved
  * @param int|string $valign reserved
  * @param  string $bgcolor square background color in #rrggbb format
  * @param  string $destformat image destination format
  * @param  int $jpgQuality JEPG quality (1-100)
  * @return false|string
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  */
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null)
 {
     if (($s = getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     if (!$jpgQuality) {
         $jpgQuality = $this->options['jpgQuality'];
     }
     elFinder::extendTimeLimit(300);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $ani = $img->getNumberImages() > 1;
             if ($ani && is_null($destformat)) {
                 $img1 = new Imagick();
                 $img1->setFormat('gif');
                 $img = $img->coalesceImages();
                 do {
                     $gif = new Imagick();
                     $gif->newImage($width, $height, new ImagickPixel($bgcolor));
                     $gif->setImageColorspace($img->getImageColorspace());
                     $gif->setImageFormat('gif');
                     $gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                     $gif->setImageDelay($img->getImageDelay());
                     $gif->setImageIterations($img->getImageIterations());
                     $img1->addImage($gif);
                     $gif->clear();
                 } while ($img->nextImage());
                 $img1 = $img1->optimizeImageLayers();
                 $result = $img1->writeImages($path, true);
             } else {
                 if ($ani) {
                     $img->setFirstIterator();
                 }
                 $img1 = new Imagick();
                 $img1->newImage($width, $height, new ImagickPixel($bgcolor));
                 $img1->setImageColorspace($img->getImageColorspace());
                 $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                 $result = $this->imagickImage($img1, $path, $destformat, $jpgQuality);
             }
             $img1->clear();
             $img->clear();
             return $result ? $path : false;
             break;
         case 'convert':
             extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
             if ($bgcolor === 'transparent') {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $cmd = sprintf('convert -size %dx%d "xc:%s" png:- | convert%s%s png:-  %s -geometry +%d+%d -compose over -composite%s %s', $width, $height, $bgcolor, $coalesce, $jpgQuality, $quotedPath, $x, $y, $deconstruct, $quotedDstPath);
             $result = false;
             if ($this->procExec($cmd) === 0) {
                 $result = true;
             }
             return $result ? $path : false;
             break;
         case 'gd':
             $img = $this->gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 $this->gdImageBackground($tmp, $bgcolor);
                 if ($bgcolor === 'transparent' && ($destformat === 'png' || $s[2] === IMAGETYPE_PNG)) {
                     $bgNum = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
                     imagefill($tmp, 0, 0, $bgNum);
                 }
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 $result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
Exemple #12
0
 public function thumb($width, $height, $type = THINKIMAGE_THUMB_SCALE)
 {
     if (empty($this->img)) {
         throw new Exception("没有可以被缩略的图像资源");
     }
     $w = $this->info["width"];
     $h = $this->info["height"];
     switch ($type) {
         case THINKIMAGE_THUMB_SCALE:
             if ($w < $width && $h < $height) {
                 return NULL;
             }
             $scale = min($width / $w, $height / $h);
             $x = $y = 0;
             $width = $w * $scale;
             $height = $h * $scale;
             break;
         case THINKIMAGE_THUMB_CENTER:
             $scale = max($width / $w, $height / $h);
             $w = $width / $scale;
             $h = $height / $scale;
             $x = ($this->info["width"] - $w) / 2;
             $y = ($this->info["height"] - $h) / 2;
             break;
         case THINKIMAGE_THUMB_NORTHWEST:
             $scale = max($width / $w, $height / $h);
             $x = $y = 0;
             $w = $width / $scale;
             $h = $height / $scale;
             break;
         case THINKIMAGE_THUMB_SOUTHEAST:
             $scale = max($width / $w, $height / $h);
             $w = $width / $scale;
             $h = $height / $scale;
             $x = $this->info["width"] - $w;
             $y = $this->info["height"] - $h;
             break;
         case THINKIMAGE_THUMB_FILLED:
             if ($w < $width && $h < $height) {
                 $scale = 1;
             } else {
                 $scale = min($width / $w, $height / $h);
             }
             $neww = $w * $scale;
             $newh = $h * $scale;
             $posx = ($width - $w * $scale) / 2;
             $posy = ($height - $h * $scale) / 2;
             $newimg = new Imagick();
             $newimg->newImage($width, $height, "white", $this->info["type"]);
             if ("gif" == $this->info["type"]) {
                 $imgs = $this->img->coalesceImages();
                 $img = new Imagick();
                 $this->img->destroy();
                 do {
                     $image = $this->_fill($newimg, $posx, $posy, $neww, $newh, $imgs);
                     $img->addImage($image);
                     $img->setImageDelay($imgs->getImageDelay());
                     $img->setImagePage($width, $height, 0, 0);
                     $image->destroy();
                 } while ($imgs->nextImage());
                 $this->img->destroy();
                 $this->img = $img->deconstructImages();
                 $imgs->destroy();
                 $img->destroy();
             } else {
                 $img = $this->_fill($newimg, $posx, $posy, $neww, $newh);
                 $this->img->destroy();
                 $this->img = $img;
             }
             $this->info["width"] = $width;
             $this->info["height"] = $height;
             return NULL;
         case THINKIMAGE_THUMB_FIXED:
             $x = $y = 0;
             break;
         default:
             throw new Exception("不支持的缩略图裁剪类型");
     }
     $this->crop($w, $h, $x, $y, $width, $height);
 }
Exemple #13
0
 public function add_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $draw->composite($watermark->getImageCompose(), $x, $y, $watermark->getImageWidth(), $watermark->getimageheight(), $watermark);
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
Exemple #14
0
function ImagickResizeImage($srcFile, $destFile, $new_w, $new_h, $zhenshu = false)
{
    if ($new_w <= 0 || $new_h <= 0 || !file_exists($srcFile)) {
        return false;
    }
    $src = new Imagick($srcFile);
    $image_format = strtolower($src->getImageFormat());
    if ($image_format != 'jpeg' && $image_format != 'gif' && $image_format != 'png' && $image_format != 'jpg' && $image_format != 'bmp') {
        return false;
    }
    //如果是 jpg jpeg
    if ($image_format != 'gif') {
        $dest = $src;
        $dest->thumbnailImage($new_w, $new_h, true);
        $dest->writeImage($destFile);
        $dest->clear();
        //gif需要以帧一帧的处理
    } else {
        $dest = new Imagick();
        $color_transparent = new ImagickPixel("transparent");
        //透明色
        $gif_i = 1;
        foreach ($src as $img) {
            $page = $img->getImagePage();
            $tmp = new Imagick();
            $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
            $tmp->compositeImage($img, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
            $tmp->thumbnailImage($new_w, $new_h, true);
            $dest->addImage($tmp);
            $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
            $dest->setImageDelay($img->getImageDelay());
            $dest->setImageDispose($img->getImageDispose());
            if ($zhenshu > 0) {
                if ($zhenshu <= $gif_i) {
                    break;
                }
                $gif_i++;
            }
        }
        $dest->coalesceImages();
        $dest->writeImages($destFile, true);
        $dest->clear();
    }
}
Exemple #15
0
 function GetView()
 {
     global $TMP_PATH;
     $tmp_file = ADEI::GetTmpFile();
     $servername = "localhost";
     $username = "******";
     $password = "******";
     $dbname = "HDCP10";
     $width = 800;
     $height = 600;
     $window = "1365832800-1365854400";
     $interval = explode("-", $this->window);
     $total_seconds = $interval[1] - $interval[0];
     $start = $interval[0] * 1000000;
     $end = $interval[1] * 1000000;
     $im = new Imagick();
     $draw2 = new ImagickDraw();
     $draw2->setStrokeColor("#808080");
     $draw2->setStrokeWidth(1);
     $draw2->setFontSize(72);
     $draw2->line(700, 240, 800, 240);
     $ystroke = new Imagick();
     $ystroke->newImage(800, 480, "white");
     $ystroke->setImageFormat("png");
     $ystroke->drawImage($draw2);
     $im->addImage($ystroke);
     $draw = new ImagickDraw();
     $draw->setStrokeColor("#808080");
     $draw->setStrokeWidth(100);
     $draw->setFontSize(72);
     $draw->line(100, 0, 100, 480);
     $yaxis = new Imagick();
     $yaxis->newImage(100, 480, "white");
     $yaxis->setImageFormat("png");
     $yaxis->drawImage($draw);
     $im->addImage($yaxis);
     try {
         $conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password);
         // set the PDO error mode to exception
         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $sql = "SELECT count(*) FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8";
         $stmt = $conn->query($sql);
         $row = $stmt->fetch();
         $total = $row[0];
         $sql = "SELECT img_id, image FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8 ORDER BY img_id ASC";
         $stmt = $conn->query($sql);
         while ($row = $stmt->fetchObject()) {
             if (is_null($row->image)) {
                 $im->newImage(7, 480, "white");
                 continue;
             }
             $im->readimageblob($row->image);
         }
     } catch (PDOException $e) {
         //echo "Connection failed: " . $e->getMessage();
     }
     /* Create new imagick object */
     //$im = new Imagick();
     /* create red, green and blue images */
     //$im->newImage(100, 50, "red");
     //$im->newImage(100, 50, "green");
     //$im->newImage(100, 50, "blue");
     /* Append the images into one */
     $im->resetIterator();
     $combined = $im->appendImages(false);
     /* Output the image */
     $combined->setImageFormat("png");
     /* 
     Having to do alot of resizing, i needed to know the speeds of the different resize filters.
     This was how long it took to resize a 5906x5906 JPEG image to 1181x1181.
     
     FILTER_POINT took: 0.334532976151 seconds
     FILTER_BOX took: 0.777871131897 seconds
     FILTER_TRIANGLE took: 1.3695909977 seconds
     FILTER_HERMITE took: 1.35866093636 seconds
     FILTER_HANNING took: 4.88722896576 seconds
     FILTER_HAMMING took: 4.88665103912 seconds
     FILTER_BLACKMAN took: 4.89026689529 seconds
     FILTER_GAUSSIAN took: 1.93553304672 seconds
     FILTER_QUADRATIC took: 1.93322920799 seconds
     FILTER_CUBIC took: 2.58396601677 seconds
     FILTER_CATROM took: 2.58508896828 seconds
     FILTER_MITCHELL took: 2.58368492126 seconds
     FILTER_LANCZOS took: 3.74232912064 seconds
     FILTER_BESSEL took: 4.03305602074 seconds
     FILTER_SINC took: 4.90098690987 seconds
     */
     $combined->resizeImage(1200, 600, Imagick::FILTER_LANCZOS, 1);
     #$draw3 = new ImagickDraw();
     #$draw3->setStrokeColor("black");
     //$draw3->setFillColor($fillColor);
     #$draw3->setStrokeWidth(0.1);
     #$draw3->setFontSize(8);
     #$combined->annotateImage($draw3, 0, 300, 0, "500");
     file_put_contents("{$TMP_PATH}/{$tmp_file}", $combined);
     return array("img" => array("id" => $tmp_file));
 }
 private function _imageickThumb($url, $type, $new_w = 765, $new_h = 1000, $self = false, $trim = false)
 {
     $srcFile = $url;
     if ($self) {
         $destFile = $url;
     } else {
         $destFile = $type;
     }
     if ($new_w <= 0 || !file_exists($srcFile)) {
         return false;
     }
     $src = new Imagick($srcFile);
     $image_format = strtolower($src->getImageFormat());
     if ($image_format != 'jpeg' && $image_format != 'gif' && $image_forumat != 'bmp' && $image_format != 'png' && $image_format != 'jpg') {
         return false;
     }
     $src_page = $src->getImagePage();
     $src_w = $src_page['width'];
     $rate_w = $new_w / $src_w;
     if ($rate_w >= 1) {
         return false;
     }
     if ($new_h == -1) {
         $new_h = $rate_w * $src_page['height'];
     }
     //如果是 jpg jpeg gif
     if ($image_format != 'gif') {
         $dest = $src;
         if (!$trim) {
             $dest->thumbnailImage($new_w, $new_h, true);
         } else {
             $dest->cropthumbnailImage($new_w, $new_h);
         }
         $dest->writeImage($destFile);
         $dest->clear();
         //gif需要以帧一帧的处理
     } else {
         $dest = new Imagick();
         $color_transparent = new ImagickPixel("transparent");
         //透明色
         foreach ($src as $img) {
             $page = $img->getImagePage();
             if ($new_h == -1) {
                 $new_h = $new_w / $page['width'] * $src_page['hight'];
             }
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($img, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             if (!$trim) {
                 $tmp->thumbnailImage($new_w, $new_h, true);
             } else {
                 $tmp->cropthumbnailImage($new_w, $new_h);
             }
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($img->getImageDelay());
             $dest->setImageDispose($img->getImageDispose());
         }
         $dest->coalesceImages();
         $dest->writeImages($destFile, true);
         $dest->clear();
     }
 }
Exemple #17
0
    //    var_dump($identifyInfo);
    $imagickFrame->writeImage($frame . "debug.gif");
    //if (false) {
    $paletteImage = clone $imagickFrame;
    $paletteImage->quantizeImage(256, Imagick::COLORSPACE_YIQ, 0, false, false);
    //$imagickFrame->setImageDepth(8);
    //$imagickFrame->quantizeImage(15,Imagick::COLORSPACE_TRANSPARENT,0,false,false);
    //Imagick::mapImage ( Imagick $map , bool $dither )
    $imagickFrame->remapImage($paletteImage, Imagick::DITHERMETHOD_FLOYDSTEINBERG);
    //}
    //Imagick::DITHERMETHOD_RIEMERSMA
    //Imagick::DITHERMETHOD_FLOYDSTEINBERG
    //6.9meg
    //$imagickFrame->quantizeImage(255, Imagick::COLORSPACE_RGB, 0, true, false );
    //orderedPosterizeImage ( string $threshold_map [, int $channel = Imagick::CHANNEL_ALL ] )
    //posterizeImage ( int $levels , bool $dither )
    //$imagickFrame->remapimage()
    $imagickFrame->setImageDelay($frameDelay);
    $animation->addImage($imagickFrame);
}
//Zero default - 8 biggest tree
//$animation->quantizeImages(255, Imagick::COLORSPACE_RGB, 0, false, false );
//$animation->quantizeImages(255, Imagick::COLORSPACE_RGB, 8, true, false );
//Imagick::clutImage ( Imagick $lookup_table [, float $channel = Imagick::CHANNEL_DEFAULT ] )
$animation->setFormat('gif');
$animation->setImageFormat('gif');
$outputGif = $animation->deconstructImages();
$outputFilename = $animDir . ".gif";
$outputGif->writeImages($outputFilename, true);
$filesize = filesize($outputFilename);
echo "output is {$outputFilename}, filesize is {$filesize} \n";
 public function add_full_watermark($path, $x = 0, $y = 0)
 {
     $watermark = new Imagick($path);
     $draw = new ImagickDraw();
     $image = $this->image;
     $image_w = $image->getImageWidth();
     $image_h = $image->getimageheight();
     $water_w = $watermark->getImageWidth();
     $water_h = $watermark->getimageheight();
     $a = floor($image_w / $water_w);
     $b = floor($image_h / $water_h);
     //$offset_x = ($image_w>$water_w)?floor($image_w%$water_w/2):0;
     //$offset_y = ($image_h>$water_h)?floor($image_h%$water_h/2):0;
     $offset_x = $offset_y = 0;
     for ($i = 0; $i <= $a; $i++) {
         for ($j = 0; $j <= $b; $j++) {
             $draw->composite($watermark->getImageCompose(), $i * $water_w + $offset_x, $j * $water_h + $offset_y, $water_w, $water_h, $watermark);
         }
     }
     if ($this->type == 'gif') {
         $image = $this->image;
         $canvas = new Imagick();
         $images = $image->coalesceImages();
         foreach ($image as $frame) {
             $img = new Imagick();
             $img->readImageBlob($frame);
             $img->drawImage($draw);
             $canvas->addImage($img);
             $canvas->setImageDelay($img->getImageDelay());
         }
         $image->destroy();
         $this->image = $canvas;
     } else {
         $this->image->drawImage($draw);
     }
 }
Exemple #19
0
 function waterMarkFont()
 {
     if ($this->param['water_mark_color']) {
         $color = $this->param['water_mark_color'];
     } else {
         $color = '#000000';
     }
     $r = hexdec(substr($color, 1, 2));
     $g = hexdec(substr($color, 3, 2));
     $b = hexdec(substr($color, 5, 2));
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel($color));
     //设置填充颜色
     $draw->setFont($this->param['water_mark_font']);
     //设置文本字体,要求ttf或者ttc字体,可以绝对或者相对路径
     $draw->setFontSize($this->param['water_mark_fontsize']);
     //设置字号
     switch ($this->param['water_mark_pos']) {
         case 0:
         case 1:
             $gravity = Imagick::GRAVITY_NORTHWEST;
             //'NorthWest';
             break;
         case 2:
             $gravity = Imagick::GRAVITY_NORTH;
             //'North';
             break;
         case 3:
             $gravity = Imagick::GRAVITY_NORTHEAST;
             //'NorthEast';
             break;
         case 4:
             $gravity = Imagick::GRAVITY_WEST;
             //'West';
             break;
         case 5:
             $gravity = Imagick::GRAVITY_CENTER;
             //'Center';
             break;
         case 6:
             $gravity = Imagick::GRAVITY_EAST;
             //'East';
             break;
         case 7:
             $gravity = Imagick::GRAVITY_SOUTHWEST;
             //'SouthWest';
             break;
         case 8:
             $gravity = Imagick::GRAVITY_SOUTH;
             //'South';
             break;
         case 9:
             $gravity = Imagick::GRAVITY_SOUTHEAST;
             break;
     }
     $draw->setGravity($gravity);
     if ($this->image_type == 'GIF') {
         $color_transparent = new ImagickPixel("transparent");
         $dest = new Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($frame, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             $tmp->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($frame->getImageDelay());
             $dest->setImageDispose($frame->getImageDispose());
         }
         $dest->coalesceImages();
         $this->image->destroy();
         $this->image = $dest;
     } else {
         if ($this->param['water_mark_opacity']) {
             $draw->setFillOpacity($this->param['water_mark_opacity'] / 100);
         }
         $this->image->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
     }
 }
Exemple #20
0
<?php

$url1 = $_GET['url1'];
$url2 = $_GET['url2'];
$im = new Imagick();
$im1 = new Imagick($url1);
$im2 = new Imagick($url2);
$im->addImage($im1);
$im->addImage($im2);
$im->resetIterator();
$combined = $im->appendImages(false);
$combined->setImageFormat('jpg');
header('Content-Type: image/jpg');
echo $combined;
Exemple #21
0
 * Time: 上午9:57
 */
define('DS', DIRECTORY_SEPARATOR);
$baseUri = dirname(__FILE__) . DS . 'images' . DS;
$combined = new Imagick();
for ($i = 1; $i < 3; $i++) {
    $im = new Imagick($baseUri . '00' . $i . '.jpg');
    $im->resizeImage(595, 842, imagick::FILTER_LANCZOS, 1, true);
    add_text($im, 'hello world', 100, 200, 0, array("font" => "SimHei", "font_size" => "30", "fill_color" => "black", "back_color" => "none"));
    $mask = new Imagick($baseUri . 'mask.png');
    $overlay = new Imagick($baseUri . 'overlay.png');
    add_mask($im, $mask);
    add_overlay($im, $overlay);
    $mask->destroy();
    $overlay->destroy();
    $combined->addImage($im);
    $im->destroy();
}
#$combined->resetIterator();
#$combined = $combined->appendImages(true);
#$combined->setPage(595,842,0,0);
$combined->setImageFormat('pdf');
#$fp = fopen('/home/gujc/Downloads/test.pdf','wb');
#$combined->writeImagesFile($fp);
$combined->writeImages($baseUri . 'test.pdf', true);
#$combined->destroy();
$reload = new Imagick($baseUri . 'test.pdf');
#$type=$combined->getFormat();
header('Content-type: pdf');
#header('Content-Disposition: attachment;filename="test.pdf"');
echo $reload->getImagesBlob();
 public function addFont($text, $font, $startX = 0, $startY = 12, $color = 'black', $fontSize = 12, $alpha = 1, $degree = 0)
 {
     if (!$text) {
         return $this;
     }
     if (!is_readable($font)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,font:' . $font, '字型檔案不存在!');
     }
     if (!($startX >= 0 && $startY >= 0)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '起始點錯誤,startX:' . $startX . ',startY:' . $startY, '水平、垂直的起始點一定要大於 0!');
     }
     if (!is_string($color)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '色碼錯誤!', '請確認色碼格式,目前只支援 字串HEX 格式!');
     }
     if (!($fontSize > 0)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,fontSize:' . $fontSize, '文字大小一定要大於 0!');
     }
     if (!($alpha && is_numeric($alpha) && $alpha >= 0 && $alpha <= 1)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '參數錯誤,alpha:' . $alpha, '參數 alpha 一定要是 0 或 1!');
     }
     if (!is_numeric($degree %= 360)) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', '角度一定要是數字,degree:' . $degree, '請確認 GD 函式庫中是否有支援 imagerotate 函式!');
     }
     if (!($draw = $this->_createFont($font, $fontSize, $color, $alpha))) {
         throw new ImageUtilityException('ImageImagickUtility 錯誤!', ' Create 文字物件失敗', '請程式設計者確認狀況!');
     }
     if ($this->format == 'gif') {
         $newImage = new Imagick();
         $newImage->setFormat($this->format);
         $imagick = $this->image->clone()->coalesceImages();
         do {
             $temp = new Imagick();
             $temp->newImage($this->dimension['width'], $this->dimension['height'], new ImagickPixel('transparent'));
             $temp->compositeImage($imagick, imagick::COMPOSITE_DEFAULT, 0, 0);
             $temp->annotateImage($draw, $startX, $startY, $degree, $text);
             $newImage->addImage($temp);
             $newImage->setImageDelay($imagick->getImageDelay());
         } while ($imagick->nextImage());
     } else {
         $newImage = $this->image->clone();
         $newImage->annotateImage($draw, $startX, $startY, $degree, $text);
     }
     return $this->_updateImage($newImage);
 }
Exemple #23
0
 /**
  * 截取图片
  *
  * @param int $x 开始坐标x
  * @param int $y 坐标y
  * @param int $width
  * @param int $height
  * @param string $savepath 文件存放路径,未提供则修改当前
  */
 public function watchmark($x, $y, $savepath = NULL)
 {
     if (!$this->waterImage instanceof \Imagick) {
         throw new MediaException('Watermark source is invalid.');
     }
     if ($format == 'GIF') {
         $format = $this->getImageFormat();
         $transparent = new \ImagickPixel("rgba(0, 0, 0, 0)");
         // 透明色
         $tmpImage = new \Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new \Imagick();
             $tmp->newImage($page['width'], $page['height'], $transparent, $format);
             $tmp->compositeImage($frame, \Imagick::COMPOSITE_DEFAULT, $page['x'], $page['y']);
             if (min($this->getOriginalSize()) > $this->waterStart) {
                 $tmp->compositeImage($this->waterImage, \Imagick::COMPOSITE_DEFAULT, $x, $y);
             }
             $tmpImage->addImage($tmp);
             $tmpImage->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $tmpImage->setImageDelay($frame->getImageDelay());
             $tmpImage->setImageDispose($frame->getImageDispose());
         }
     } else {
         $tmpImage = new \Imagick();
         $tmpImage->addimage($this->image);
         if (min($this->getOriginalSize()) > $this->waterStart) {
             $tmpImage->compositeImage($this->waterImage, \Imagick::COMPOSITE_DEFAULT, $x, $y);
         }
     }
     if ($savepath == NULL) {
         //缩放当前
         $this->image = $tmpImage;
     } else {
         //写入储存
         $this->writeToPath($savepath, $tmpImage);
     }
     return $this;
 }
Exemple #24
0
$combined->setImageFormat("png");
// should be 50, dont know why there's 3px offset
$combined->resizeImage($width, $height - 53, Imagick::FILTER_LANCZOS, 1);
$draw = new ImagickDraw();
/* Font properties */
$draw->setFont('Arial');
$draw->setFontSize(12);
$draw->setFillColor($color);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
$runner = $start;
$axis_interval = $width / 24;
$i = 0;
while ($runner < $end) {
    $text = date('H:s', $runner / 1000000);
    $metrics = $image->queryFontMetrics($draw, $text);
    $draw->annotation($i * $axis_interval, $metrics['ascender'] + 20, $text);
    $runner = $runner + $step;
    $i++;
}
$xaxis = new Imagick();
$xaxis->newImage($width, 50, $background);
$xaxis->setImageFormat('png');
$xaxis->drawImage($draw);
$with_axes->addImage($combined);
$with_axes->addImage($xaxis);
$with_axes->resetIterator();
$output = $with_axes->appendImages(true);
file_put_contents("{$TMP_PATH}/{$tmp_file}", $output);
echo json_encode($tmp_file);
//echo json_encode($end);
Exemple #25
0
 public function joinArchiveContents($pa_files, $pa_options = array())
 {
     if (!is_array($pa_files)) {
         return false;
     }
     $vs_archive_original = tempnam(caGetTempDirPath(), "caArchiveOriginal");
     @rename($vs_archive_original, $vs_archive_original . ".tif");
     $vs_archive_original = $vs_archive_original . ".tif";
     $vo_orig = new Imagick();
     foreach ($pa_files as $vs_file) {
         if (file_exists($vs_file)) {
             $vo_imagick = new Imagick();
             if ($vo_imagick->readImage($vs_file)) {
                 $vo_orig->addImage($vo_imagick);
             }
         }
     }
     if ($vo_orig->getNumberImages() > 0) {
         if ($vo_orig->writeImages($vs_archive_original, true)) {
             return $vs_archive_original;
         }
     }
     return false;
 }
Exemple #26
0
 /**
  * 创建图片
  * @param array $options 参数数组
  * 必须填写的参数:
  *   save_type: int 保存类型 1:保存图片路径自定义 2:保存后的图片覆盖原图片
  * 选填的参数:
  *   save_path: string 图片保存地址,包括目录和文件名
  *   resize_width: int 保存后图片的宽,默认取原图宽
  *   resize_height: int 保存后图片的高,默认取原图高
  *   quality: int 图片压缩质量,1-100,数字越大质量越好,默认取85
  * @return array
  */
 public function createImage($options)
 {
     $resArr = ['code' => 0];
     $acceptType = ['image/png', 'image/jpeg', 'image/gif'];
     if ($this->image == null) {
         $resArr['code'] = 1;
         $resArr['message'] = '打开图片失败';
     } else {
         if (!in_array($this->mimeType, $acceptType)) {
             $resArr['code'] = 2;
             $resArr['message'] = '图片类型不支持';
         } else {
             if ($options['save_type'] == 1) {
                 $savePath = str_replace('\\', '/', $options['save_path']);
             } else {
                 if ($options['save_type'] == 2) {
                     $savePath = $this->originalName;
                 } else {
                     $resArr['code'] = 3;
                     $resArr['message'] = '保存类型不正确';
                     return $resArr;
                 }
             }
             $resize_width = isset($options['resize_width']) && (int) $options['resize_width'] > 0 ? (int) $options['resize_width'] : $this->originalWidth;
             $resize_height = isset($options['resize_height']) && (int) $options['resize_height'] > 0 ? (int) $options['resize_height'] : $this->originalHeight;
             $quality = isset($options['quality']) && (int) $options['quality'] > 0 && (int) $options['quality'] <= 100 ? (int) $options['quality'] : 85;
             $now_quality = $this->image->getImageCompressionQuality();
             if ($now_quality == 0) {
                 $need_quality = $quality;
             } else {
                 $need_quality = ceil($now_quality * $quality / 100);
             }
             if ($this->mimeType == 'image/gif') {
                 //处理gif动态图片
                 $image = $this->image;
                 $images = $image->coalesceImages();
                 $canvas = new \Imagick();
                 foreach ($images as $eImage) {
                     $img = new \Imagick();
                     $img->readImageBlob($eImage);
                     $img->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $img->setImageCompressionQuality($need_quality);
                     $canvas->addImage($img);
                     $canvas->setImageDelay($img->getImageDelay());
                     $img->destroy();
                 }
                 $this->image = $canvas;
                 $image->destroy();
                 $canvas->destroy();
             } else {
                 if ($this->mimeType == 'image/jpeg') {
                     $this->image->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $this->image->setImageCompression(\Imagick::COMPRESSION_JPEG);
                     $this->image->setImageCompressionQuality($need_quality);
                 } else {
                     $this->image->resizeImage($resize_width, $resize_height, \Imagick::FILTER_CATROM, 1, true);
                     $this->image->setImageCompressionQuality($need_quality);
                 }
             }
             $writeRes = $this->image->writeImage($savePath);
             if ($writeRes) {
                 //修改写入成功后文件的操作权限
                 chmod($savePath, 0777);
                 $resArr['data'] = ['image_name' => $savePath, 'image_width' => $this->image->getImageWidth(), 'image_height' => $this->image->getImageHeight()];
             } else {
                 $resArr['code'] = 4;
                 $resArr['message'] = '写入文件失败';
             }
         }
     }
     return $resArr;
 }
 /**
  * Put image to square
  *
  * @param  string   $path               image file
  * @param  int      $width              square width
  * @param  int      $height             square height
  * @param  int	    $align              reserved
  * @param  int 	    $valign             reserved
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     /* Coordinates for image over square aligning */
     $y = ceil(abs($height - $s[1]) / 2);
     $x = ceil(abs($width - $s[0]) / 2);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $ani = $img->getNumberImages() > 1;
             if ($ani && is_null($destformat)) {
                 $img1 = new Imagick();
                 $img1->setFormat('gif');
                 $img = $img->coalesceImages();
                 do {
                     $gif = new Imagick();
                     $gif->newImage($width, $height, new ImagickPixel($bgcolor));
                     $gif->setImageColorspace($img->getImageColorspace());
                     $gif->setImageFormat('gif');
                     $gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                     $gif->setImageDelay($img->getImageDelay());
                     $gif->setImageIterations($img->getImageIterations());
                     $img1->addImage($gif);
                     $gif->destroy();
                 } while ($img->nextImage());
                 $img1 = $img1->optimizeImageLayers();
                 $result = $img1->writeImages($path, true);
             } else {
                 if ($ani) {
                     $img->setFirstIterator();
                 }
                 $img1 = new Imagick();
                 $img1->newImage($width, $height, new ImagickPixel($bgcolor));
                 $img1->setImageColorspace($img->getImageColorspace());
                 $img1->setImageFormat($destformat != null ? $destformat : $img->getFormat());
                 $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                 $result = $img1->writeImage($path);
             }
             $img1->destroy();
             $img->destroy();
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                 self::gdImageBackground($tmp, $bgcolor);
                 if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
                     return false;
                 }
                 $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
Exemple #28
0
 function GetView()
 {
     global $TMP_PATH;
     $tmp_file = ADEI::GetTmpFile();
     $im = new Imagick();
     $tmp = new Imagick();
     $image = new Imagick();
     $final = new Imagick();
     $with_axes = new Imagick();
     $output = new Imagick();
     $tick = new ImagickDraw();
     $ceiling = new ImagickDraw();
     $color = new ImagickPixel('#666666');
     $background = new ImagickPixel('none');
     // Transparent
     date_default_timezone_set('UTC');
     $servername = "localhost";
     $username = "******";
     $password = "******";
     $dbname = "HDCP10";
     $req = $this->req->CreateGroupRequest();
     $req = $this->req->CreateDataRequest();
     $fstart = $req->GetProp("view_pb_start", 0);
     $width = $req->GetProp("control_width", 800);
     $height = $req->GetProp("control_height", 600);
     $height = $height - 180;
     // 60px for the xaxis (50px)
     $start = 1367366400000000.0;
     // GMT: Wed, 01 May 2013 00:00:00 GMT
     $end = 1367452800000000.0;
     // GMT: Thu, 02 May 2013 00:00:00 GMT
     //$end = 1367539200000000; // GMT: Fri, 03 May 2013 00:00:00 GMT
     $current = $start;
     $step = 3600000000.0;
     try {
         $conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password);
         // set the PDO error mode to exception
         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         while (true) {
             if ($current >= $end) {
                 break;
             }
             $start_interval = $current;
             $end_interval = $start_interval + $step;
             $sql = "SELECT img_id, image, timestamp FROM Profiles_060_WTH_STATIC_EL90_Images_Stitch_Im1_3600 WHERE timestamp >= " . $start_interval . " AND timestamp < " . $end_interval;
             $stmt = $conn->query($sql);
             $row = $stmt->fetchObject();
             if ($row == false) {
                 $im->newImage($width, $height - $height * 20 / 100, "white");
             } else {
                 if (is_null($row->image)) {
                     $im->newImage($width, $height - $height * 20 / 100, "white");
                 } else {
                     $im->readimageblob($row->image);
                     $im->resizeImage($width, $height - $height * 20 / 100, Imagick::FILTER_LANCZOS, 1);
                 }
             }
             #$text = date('H:s', ($current / 1000000));
             #$draw = new ImagickDraw();
             $tick = new ImagickDraw();
             $ceiling = new ImagickDraw();
             /* Font properties */
             #$draw->setFont('Arial');
             #$draw->setFontSize(200);
             #$draw->setFillColor($color);
             #$draw->setStrokeAntialias(true);
             #$draw->setTextAntialias(true);
             /* Get font metrics */
             #$metrics = $image->queryFontMetrics($draw, $text);
             /* Create text */
             #$draw->annotation(0, $metrics['ascender']+20, $text);
             $tick->setStrokeWidth(10);
             $tick->setStrokeColor($color);
             $tick->setFillColor($color);
             $tick->line(0, 0, 0, 20);
             //imageline($image, $width/2, 0, $width/2, 50, $color);
             $ceiling->setStrokeColor($color);
             $ceiling->setFillColor($color);
             $ceiling->line(0, 0, $width, 0);
             /* Create image */
             $image->newImage($width, 20, $background);
             $image->setImageFormat('png');
             #$image->drawImage($draw);
             $image->drawImage($tick);
             $image->drawImage($ceiling);
             $im->addImage($image);
             $im->resetIterator();
             $tmp = $im->appendImages(true);
             $final->addImage($tmp);
             $current = $end_interval;
             $im->clear();
             $image->clear();
             $tmp->clear();
             $tick->clear();
             $ceiling->clear();
         }
     } catch (PDOException $e) {
         //echo "Connection failed: " . $e->getMessage();
     }
     /* Append the images into one */
     $final->resetIterator();
     $combined = $final->appendImages(false);
     /* Output the image */
     $combined->setImageFormat("png");
     $combined->resizeImage($width, $height - $height * 20 / 100, Imagick::FILTER_LANCZOS, 1);
     $draw = new ImagickDraw();
     /* Font properties */
     $draw->setFont('Arial');
     $draw->setFontSize(12);
     $draw->setFillColor($color);
     $draw->setStrokeAntialias(true);
     $draw->setTextAntialias(true);
     $runner = $start;
     $axis_interval = $width / 24;
     $i = 0;
     while ($runner < $end) {
         $text = date('H:s', $runner / 1000000);
         $metrics = $image->queryFontMetrics($draw, $text);
         $draw->annotation($i * $axis_interval, $metrics['ascender'] + 20, $text);
         $runner = $runner + $step;
         $i++;
     }
     $xaxis = new Imagick();
     $xaxis->newImage($width, 50, $background);
     $xaxis->setImageFormat('png');
     $xaxis->drawImage($draw);
     $with_axes->addImage($combined);
     $with_axes->addImage($xaxis);
     $with_axes->resetIterator();
     $output = $with_axes->appendImages(true);
     file_put_contents("{$TMP_PATH}/{$tmp_file}", $output);
     return array("img" => array("id" => $tmp_file, "yaxis" => "testest"), "div" => array("class" => "image-player", "xml" => "<div id='media'>" . "<div style='width:100px; margin: 0 auto;'>1367539200000000</div>" . "<div id='jet' class='colormap'></div>" . "<div class='range'><p class='lower'>-2</p><p class='upper'>2</p></div>" . "<div style='clear: both;'></div>" . "<div id='media-controls'>" . "<button id='play-pause-button' title='play' onclick='togglePlayPause();'>Play</button>" . "<button id='stop-button' title='stop' onclick='stopPlay();'>Stop</button>" . "<progress id='progress-bar' min='0' max='100' value='0' style='width:" . ($width - $width * 10 / 100) . "px'>0% played</progress>" . "</div>" . "</div>" . "<div id='timestamp1' style='display: none;' data='" . $start . "'></div>" . "<div id='timestamp2' style='display: none;' data='0'></div>"));
 }
Exemple #29
0
 /**
  * 生成缩略图
  * @param  integer $width  缩略图最大宽度
  * @param  integer $height 缩略图最大高度
  * @param  integer $type   缩略图裁剪类型
  */
 public function thumb($width, $height, $type = Image::IMAGE_THUMB_SCALE)
 {
     if (empty($this->img)) {
         throw new Exception('没有可以被缩略的图像资源');
     }
     //原图宽度和高度
     $w = $this->info['width'];
     $h = $this->info['height'];
     /* 计算缩略图生成的必要参数 */
     switch ($type) {
         /* 等比例缩放 */
         case Image::IMAGE_THUMB_SCALING:
             //原图尺寸小于缩略图尺寸则不进行缩略
             if ($w < $width && $h < $height) {
                 return;
             }
             //计算缩放比例
             $scale = min($width / $w, $height / $h);
             //设置缩略图的坐标及宽度和高度
             $x = $y = 0;
             $width = $w * $scale;
             $height = $h * $scale;
             break;
             /* 居中裁剪 */
         /* 居中裁剪 */
         case Image::IMAGE_THUMB_CENTER:
             //计算缩放比例
             $scale = max($width / $w, $height / $h);
             //设置缩略图的坐标及宽度和高度
             $w = $width / $scale;
             $h = $height / $scale;
             $x = ($this->info['width'] - $w) / 2;
             $y = ($this->info['height'] - $h) / 2;
             break;
             /* 左上角裁剪 */
         /* 左上角裁剪 */
         case Image::IMAGE_THUMB_NORTHWEST:
             //计算缩放比例
             $scale = max($width / $w, $height / $h);
             //设置缩略图的坐标及宽度和高度
             $x = $y = 0;
             $w = $width / $scale;
             $h = $height / $scale;
             break;
             /* 右下角裁剪 */
         /* 右下角裁剪 */
         case Image::IMAGE_THUMB_SOUTHEAST:
             //计算缩放比例
             $scale = max($width / $w, $height / $h);
             //设置缩略图的坐标及宽度和高度
             $w = $width / $scale;
             $h = $height / $scale;
             $x = $this->info['width'] - $w;
             $y = $this->info['height'] - $h;
             break;
             /* 填充 */
         /* 填充 */
         case Image::IMAGE_THUMB_FILLED:
             //计算缩放比例
             if ($w < $width && $h < $height) {
                 $scale = 1;
             } else {
                 $scale = min($width / $w, $height / $h);
             }
             //设置缩略图的坐标及宽度和高度
             $neww = $w * $scale;
             $newh = $h * $scale;
             $posx = ($width - $w * $scale) / 2;
             $posy = ($height - $h * $scale) / 2;
             //创建一张新图像
             $newimg = new Imagick();
             $newimg->newImage($width, $height, 'white', $this->info['type']);
             if ('gif' == $this->info['type']) {
                 $imgs = $this->img->coalesceImages();
                 $img = new Imagick();
                 $this->img->destroy();
                 //销毁原图
                 //循环填充每一帧
                 do {
                     //填充图像
                     $image = $this->_fill($newimg, $posx, $posy, $neww, $newh, $imgs);
                     $img->addImage($image);
                     $img->setImageDelay($imgs->getImageDelay());
                     $img->setImagePage($width, $height, 0, 0);
                     $image->destroy();
                     //销毁零时图片
                 } while ($imgs->nextImage());
                 //压缩图片
                 $this->img->destroy();
                 $this->img = $img->deconstructImages();
                 $imgs->destroy();
                 //销毁零时图片
                 $img->destroy();
                 //销毁零时图片
             } else {
                 //填充图像
                 $img = $this->_fill($newimg, $posx, $posy, $neww, $newh);
                 //销毁原图
                 $this->img->destroy();
                 $this->img = $img;
             }
             //设置新图像属性
             $this->info['width'] = $width;
             $this->info['height'] = $height;
             return;
             /* 固定 */
         /* 固定 */
         case Image::IMAGE_THUMB_FIXED:
             $x = $y = 0;
             break;
         default:
             throw new Exception('不支持的缩略图裁剪类型');
     }
     /* 裁剪图像 */
     $this->crop($w, $h, $x, $y, $width, $height);
 }
Exemple #30
0
 $stmt = $conn->query($sql);
 $row = $stmt->fetchObject();
 if ($row == false) {
     $im->newImage($width, $height, "transparent");
 } else {
     if (is_null($row->image)) {
         $im->newImage($width, $height, "transparent");
     } else {
         $range_start = $row->RG_start;
         $height_bot = $height / 8000 * $range_start;
         $height_top = $height - $height_bot;
         $image_top->readimageblob($row->image);
         $image_top->resizeImage($width, $height_top, Imagick::FILTER_LANCZOS, 1);
         $image_bot->newImage($width, $height_bot, "transparent");
         $image_bot->setImageFormat('png');
         $image_tmp->addImage($image_top);
         $image_tmp->addImage($image_bot);
         $image_tmp->resetIterator();
         $im = $image_tmp->appendImages(true);
         $im->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1);
     }
 }
 $tick = new ImagickDraw();
 $tick->setStrokeWidth(10);
 $tick->setStrokeColor($color);
 $tick->setFillColor($color);
 $tick->line(0, 0, 0, 20);
 $ceiling = new ImagickDraw();
 $ceiling->setStrokeColor($color);
 $ceiling->setFillColor($color);
 $ceiling->line(0, 0, $width, 0);