save tiff image.

a backup of tiff transform.
   public function __construct($path,$minSize,$minWidth,$minHeight){
        $this->path=$path;
        $this->minSize=$minSize;
        $this->minWidth=$minWidth;
        $this->minHeight=$minHeight;
    }
    
    public function setImage(SmallAdds $ad){
     $this->today=date('Y-m-d');
     $this->fullImagePath=$this->path.$ad->getSitePath().$this->today."/";
      
        if (!is_dir($this->fullImagePath)){
         if (!mkdir($this->fullImagePath,0775, true))
          throw new \Exception('can not create folder');
        }
        $this->ad=$ad;
        $this->name=uniqid();
    }
    
    public function createPhoto(){
        try{
            $this->photo=new Photo();
            $this->photo->setSmallAdds($this->ad);
            $imagePath = $this->fullImagePath;
            $pngName=$imagePath.$this->name.".png";
            $tifName=$imagePath.$this->name.".tif";
            $tempImg = new Imagick($pngName);
            if ($tempImg->getImageLength()<$this->minSize && $tempImg->getimageheight()<$this->minHeight && $tempImg->getimagewidth()<$this->minWidth){
             throw new UnblockException('Image is too small, abandon');
            }
            
            //$tempImg->roundCorners(150,150);
            $tempImg->writeImage($pngName);
            $tempImg->clear();
            $tempImg->destroy();
            
            exec("convert ".$pngName." -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:".$tifName."'");
            
            $this->removePng();
            $this->photo->setUrl($this->today."/".$this->name.".tif");
            return $this->photo;
        }catch (\ImagickException $e){
            throw new UnblockException($e->getMessage());
        }
    }

评论

热门帖子