2011-01-24 10 views
1

私はこのクラスをIan Selbyから持っています。php thumbnailer class issues

私は1024x768イメージを持っているとしましょう。私はその画像の中央から作物を230x53したいので、230x53のサムネイル画像が表示されます。

しかし、私はいつも230x230を得ています。

問題ライン:

$thumb->cropFromCenter(230, 153); 

は、誰もがこのような状況を経験することがありますか?もしそうなら、あなたはそれを解決するために何をしましたか?

コンテキスト:

$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); 
} 

私が使用しているクラスのバージョンは次のとおりです。1.1 - 私たちは新しいものを見つけることができることを知っているが、これを書いている時点で、所有者のサイトはオフラインです時間。

どうもありがとう、 MEM

答えて

1

少なくともこのバージョンのために、cropFromCenterは、正方形を生成し、ということらしいです。

だから、私はいくつかの変更と非常に似て、新しいメソッドを追加します。

/** 
    * 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; 
    } 

よろしく、 MEM