zxbodya / yii2-gallery-manager

93 stars 61 forks source link

How about fit preview image into preview image area? #75

Open bscheshirwork opened 5 years ago

bscheshirwork commented 5 years ago

This is some strange:

.gallery-manager .photo img {
    width: 140px;
    height: auto;
}

.gallery-manager .image-preview {
    height: 88px;
    overflow: hidden;
}
    /**
     * Widget preview height
     * @var int
     */
    public $previewHeight = 200;
    /**
     * Widget preview width
     * @var int
     */
    public $previewWidth = 200;

https://github.com/zxbodya/yii2-gallery-manager/blob/4a9ca72b36900195f34004926e593ed00cb91252/GalleryBehavior.php#L121-L127

peek 2018-12-20 14-40

bscheshirwork commented 5 years ago

So... We can change a preview size and rules:

    /**
     * Widget preview height
     * @var int
     */
    public $previewHeight = 88;
    /**
     * Widget preview width
     * @var int
     */
    public $previewWidth = 130;
            $this->versions['preview'] = function ($originalImage) {
                $imagine = new \Imagine\Imagick\Imagine();
                $image = $imagine->create(new \Imagine\Image\Box($this->previewWidth, $this->previewHeight));
                /** @var ImageInterface $originalImage */
                $thumbnail = $originalImage
                    ->thumbnail(new Box($this->previewWidth, $this->previewHeight));
                $size = $thumbnail->getSize();

                return $image->paste($thumbnail, new \Imagine\Image\Point(floor(($this->previewWidth - $size->getWidth()) / 2), floor(($this->previewHeight - $size->getHeight()) / 2)));
            };

peek 2018-12-20 16-07