开发者

php thumbnailer class issues

I have this class from Ian Selby.

Let's say I have a 1024x768 image. I would like crop 230x53 from the center of that image, so that, a 230x53 thumbnail image appears.

However, I'm always getting a 230x230 instead.

The issue line:

$thumb->cropFromCenter(230, 153);

Have anyone experience this kind of situation? And if so, what did you do to solve it?

The context:

$fileThumb = "./lib/galeria/thumb".$r["anexo"];
if (!file_exists($fileThumb)){
 $thumb = new Thumbnail("lib/galeria/".$r["anexo"]);
 $thumb->cropFromCenter(230, 153);
 $thumb->show(100,$fileThumb);
}

The class version that I'm using is: 1.1 - I know that we can find a new one, but at 开发者_StackOverflow社区the time of this writing, the owner site is offline for hours.

Thanks a lot, MEM


It seems that, at least for this version, the cropFromCenter, generates a square.

So, I end up adding a new method, very similar with a few changes.

/**
     * Crop a image from calculated center not in a square BUT
         * on a given heigth and width.
     *
     * @param int $width
     * @param int $height
     */
    public function cropFromCenterNoSquare($width, $height) {
        if($width > $this->currentDimensions['width']) $width = $this->currentDimensions['width'];
        if($height > $this->currentDimensions['height']) $height = $this->currentDimensions['height'];

        $cropX = intval(($this->currentDimensions['width'] - $width) / 2);
        $cropY = intval(($this->currentDimensions['height'] - $height) / 2);

        if(function_exists("ImageCreateTrueColor")) {
            $this->workingImage = ImageCreateTrueColor($width,$height);
        }
        else {
            $this->workingImage = ImageCreate($width,$height);
        }

        imagecopyresampled(
            $this->workingImage,
            $this->oldImage,
            0,
            0,
            $cropX,
            $cropY,
            $width,
            $height,
            $width,
            $height
        );

        $this->oldImage = $this->workingImage;
        $this->newImage = $this->workingImage;
        $this->currentDimensions['width'] = $width;
        $this->currentDimensions['height'] = $height;
    }

Regards, MEM

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜