1

写真をアップロードするときに、中央からの画像の比率に関係なく、トリミングが画像の内側にあることを確認して画像をトリミングする機能が必要です。

代替テキスト

上の画像は2592*1944です

159*129の画像を切り抜きたい

代替テキスト

これは、cakephp用のプラグイン(Miles Johnsons Upload Plugin)を使用したときに得られるものです。

誰かがこれを行うための画像トリミング関数を見つけるのを手伝ってくれるか、同じことをするアルゴリズムを手伝ってくれる人がいますか?

4

3 に答える 3

1

私はこれを使用しました: http ://shiftingpixel.com/2008/03/03/smart-image-resizer/ここにあるすべての画像サムネイルを作成しました:http://www.patriciashin.com/painting.php

于 2010-10-01T05:43:47.340 に答える
1

私はこのコードを徹底的にテストしていないと言わなければなりません、私は個人的な使用のためにそれを修正しました、そしてこれはあなたの問題を助けるはずです。

plugin / uploader / vendor/uploader.phpの関数cropを置き換えます

ライン368の近く

次の機能で

 public function crop(array $options = array(), $explicit = false) {
    if ($this->_data[$this->_current]['group'] != 'image' || !$this->_enabled) {
        return false;
    }

    $options = $options + array('location' => self::LOC_CENTER, 'quality' => 100, 'width' => null, 'height' => null, 'append' => null, 'prepend' => null);
    $width = $this->_data[$this->_current]['width'];
    $height = $this->_data[$this->_current]['height'];
    $src_x = 0;
    $src_y = 0;
    $dest_w = $width;
    $dest_h = $height;
    $location = $options['location'];

    if (is_numeric($options['width']) && is_numeric($options['height'])) {
        $newWidth = $options['width'];
        $newHeight = $options['height'];

        if ($width / $newWidth > $height / $newHeight) {
            $dest_h = $options['height'];
            $dest_w = round($width / ($height / $newHeight));
        } else {
            $dest_w = $options['width'];
            $dest_h = round($height / ($width / $newWidth));
        }
    } else {
        if ($width > $height) {
            $newWidth = $height;
            $newHeight = $height;
        } else {
            $newWidth = $width;
            $newHeight = $width;
        }

        $dest_h = $newHeight;
        $dest_w = $newWidth;
    }

    $src_x = 0;
    $src_y = 0;
    if ($dest_w > $newWidth) {
            $src_x = ceil(( ($dest_w - $newWidth) / 2) * ($height / $newHeight));
    }

    if ($dest_h > $newHeight) {
            $src_y = ceil(( ($dest_h - $newHeight) / 2) * ($width / $newWidth));
    }

    $append = '_cropped_' . $newWidth . 'x' . $newHeight;

    if ($options['append'] !== false && empty($options['append'])) {
        $options['append'] = $append;
    }

    $transform = array(
        'width' => $newWidth,
        'height' => $newHeight,
        'source_x' => $src_x,
        'source_y' => $src_y,
        'source_w' => $width,
        'source_h' => $height,
        'dest_w' => $dest_w,
        'dest_h' => $dest_h,
        'target' => $this->setDestination($this->_data[$this->_current]['name'], true, $options, false),
        'quality' => $options['quality']
    );
    if ($this->transform($transform)) {

        return $this->_returnData($transform, $append, $explicit);
    }

    return false;
}

敬具。

于 2012-02-15T13:04:29.020 に答える
1

この問題は解決されました。最新バージョンのケーキアップローダーpluignをチェックアウトしてください。 https://github.com/milesj/cake-uploader/commit/2be63f32730755cffbace17ee8fa2d686785964d

于 2012-04-15T16:37:14.587 に答える