0

PHP gd を使用して画像キャンバスを拡張しています。

    $newimage = imagecreatetruecolor($imageWidth + 840, $imageHeight);
    $color = imagecolorallocate($newimage, 0, 0, 0);
    imagefill($newimage, 0, 0, $color);
    imagecopy($newimage, $image, 0, 0, 0, 0, $imageWidth, $imageHeight);

    //get extension of the cropped image
    $ext = end(explode('.' , $imageName));

    //timestamp it
    $timestamp = time();

    //rename the new image
    $fileName = rand() . $timestamp . '.' . $ext;

    //unlink old image
    unlink($src);

    //update the DB with new imagename
    $update = array('update' => $this->image->update($imageID, $fileName));

    //Set the path for the image
    $path = 'data/gallery/' . $galleryID . '/images/album/' . $fileName;

    //create the cropped image
    imagejpeg($newimage,$path,$jpeg_quality);

これは期待どおりに機能し、キャンバスは右側の 840 ピクセルまで拡張されます。私ができるようにしたいのは、キャンバスを左の 840 ピクセルまで拡張することです。これを実現する方法がわかりません。

助けてくれてありがとう。

4

1 に答える 1

0

すべてのパラメータを解読すると、実際には非常に簡単です。

imagecopy ( resource dest_image, resource source_image, int dest_x, int dest_y, int source_x, int source_y, int source_width, int source_height)
  • コピー先の画像

  • コピー元のソース画像

  • コピー先のX座標

  • コピー先のY座標

  • コピー元のX座標

  • コピー元のy座標

  • コピーするソース画像のピクセル単位の幅

  • コピーするソース画像の高さ(ピクセル単位)

于 2013-01-10T00:32:20.433 に答える