insert — Paste over another image

Description

public Intervention\Image\Image insert(mixed $source, [integer $pos_x, integer $pos_y, [string $anchor]])

Paste a given image source over the current image with an optional position x, y and an optional anchor position. This method can be used to apply another image as watermark because the transparency values are maintained.

Parameters

source

The image source that will inserted on top of the current image. The method can handle the following types of input:

  • string - Path of the image in filesystem.
  • string - Binary image data.
  • resource - PHP resource of type gd.
  • object - Instance of Intervention\Image\Image

pos_x (optional)

Optional position of the new image on x-axis of the current image. Default: 0

pos_y (optional)

Optional position of the new image on y-axis of the current image. Default: 0

anchor (optional)

Set a position where image will be inserted. For example if you are setting the anchor to bottom-left the image will be positioned at the bottom-left border of the current image. The position of the new image will be calculated relatively to this location.

The possible values for anchor are:

  • top-left (default)
  • top
  • top-right
  • left
  • center
  • right
  • bottom-left
  • bottom
  • bottom-right

Return Values

Instance of Intervention\Image\Image

Examples

  1. // create new Intervention Image
  2. $img = Image::make('public/foo.jpg');
  3. // paste another image
  4. $img->insert('public/bar.png');
  5. // create a new Image instance for inserting
  6. $watermark = Image::make('public/watermark.png');
  7. $img->insert($watermark, 100, 100);
  8. // insert watermark at bottom-right corner
  9. $img->insert('public/watermark.png', 0, 0, 'bottom-right');

See also