Insert local image
Embed a PNG or JPEG inside a cell. Use the path-based variant when the image lives on disk, or the buffer-based variant when the bytes are already in memory (uploads, S3, streamed data, …).
Function Prototype
insertImage(int $row, int $column, string $localImagePath, double $widthScale = 1.0, double $heightScale = 1.0): self
insertImageBuffer(int $row, int $column, string $bytes, ?array $options = null): selfint $row
cell row
int $column
cell column
string $localImagePath
Path to a PNG or JPEG file.
double $widthScale
Scale the image on the X axis; the default is 1, maintaining the original width; when the value is 0.5, the image width becomes 1/2 of the original.
double $heightScale
Scale the image on the Y axis; the default is 1, maintaining the original height; when the value is 0.5, the image height becomes 1/2 of the original.
string $bytes
Raw image bytes, e.g. the return value of
file_get_contents()or a stream read.
array $options (optional, for insertImageBuffer)
All keys are optional:
x_offsetint — horizontal pixel offset
y_offsetint — vertical pixel offset
x_scaledouble — horizontal scale factor (default1.0)
y_scaledouble — vertical scale factor (default1.0)
object_positionint — anchor mode (default2)
urlstring — hyperlink the image points to
descriptionstring — accessibility / alt-text description
Example — path
Example — buffer
Last updated