2011-07-11 11 views
1

JPG画像を指定すると、水平方向に100K程度の大きさにカットします。1つの大きな画像を同じサイズの小さな画像に切り取ります

ヒントはありますか?

+0

は、あなたが何かを試してみましたか?何か問題はありますか? –

+0

圧縮率はデータの種類によって異なりますので、サイズ*で切り取ることはできません。つまり、1つの100KBイメージは、別の100KBイメージよりも大きなサイズ(幅、高さ)になります。これを避けるために、圧縮されていない形式(例:bmp)を使用することもできますが、それは通常はお勧めできません。 – binaryLV

+0

「カット」とは、偶然、サイズを変更することですか? –

答えて

0

は私に適しています...

これは、入力ファイルを取得し、指定されたサイズのタイルを作成します。過去にこの機能を使用している...

function makeTiles($name, $imageFileName, $crop_width, $crop_height) 
{ 
    $dir = "source dir"; 
    $slicesDir = "target dir"; 

    // might be good to check if $slicesDir exists etc if not create it. 

    $inputFile = $dir . $imageFileName; 

    $img = new Imagick($inputFile); 
    $imgHeight = $img->getImageHeight(); 
    $imgWidth = $img->getImageWidth(); 

     $cropWidthTimes = ceil($imgWidth/$crop_width); 
    $cropHeightTimes = ceil($imgHeight/$crop_height); 
    for($i = 0; $i < $cropWidthTimes; $i++) 
    { 
     for($j = 0; $j < $cropHeightTimes; $j++) 
     { 
      $img = new Imagick($inputFile); 
      $x = ($i * $crop_width); 
      $y = ($j * $crop_height); 
      $img->cropImage($crop_width, $crop_height, $x, $y); 
      $data = $img->getImageBlob(); 
      $newFileName = $slicesDir . $name . "_" . $x . "_" . $y . ".jpg"; 
      $result = file_put_contents ($newFileName, $data); 
     } 
    } 
}