composer require uginroot/image-resize:^1.0
$image = ImageResize::createFromString(file_get_content($path));
$image = ImageResize::createFromPath($path);
$content = file_get_content($path);
$resource = imagecreatefromstring($content);
$image = new ImageCreate($resource, $content);
$image = new ImageCreate($resource); // $image->resetOrientation() not working
ImageCreate::FORMAT_JPEG;
ImageCreate::FORMAT_PNG;
ImageCreate::FORMAT_WEBP;
$image->save($path);
// save(string $path [, int $format = ImageCreate::FORMAT_JPEG [, bool $owerwrite = false [, int $mode = 0666]]])
See this package link
echo $image->getContent();
// getContent([int $format = ImageCreate::FORMAT_JPEG]);
$image->print();
// $image->print([int $format = ImageCreate::FORMAT_JPEG]);
(string)$image === $image->getContent(ImageCreate::FORMAT_JPEG); // true
$image->copyResource();
$image->getWidth();
$image->getHeight();
Rotate photo if the set exif orientation tag
$image->resetOrientation();
$image->scale(50);
// scale(int|float 50)
original(600x300) | result(300x150) |
---|---|
$image->resize(100, 100);
// resize(int $width, int $heihht [, bool $increase = true])
original(600x300) | result(100x100) |
---|---|
$image->resizeToHeight(100);
// resizeToHeight(int $height [, bool $increase = true])
original(600x300) | result(100x200) |
---|---|
$image->resizeToWidth(100);
// resizeToWidth(int $width [, bool $increase = true])
original(600x300) | result(100x50) |
---|---|
$image->resizeToLongSide(100);
// resizeToLongSide(int $side [, $increase = true])
original(600x300) | result(100x50) |
---|---|
$image->resizeToShortSide(100);
// resizeToShortSide(int $side [, $increase = true])
original(600x300) | result(100x200) |
---|---|
$image->resizeToBestFit(100, 100);
// resizeToBestFit(int $width, int $height [, $increase = true])
original(600x300) | result(100x50) |
---|---|
$image->resizeToWorstFit(100, 100);
// resizeToWorstFit(int $width, int $height [, $increase = true])
original(600x300) | result(100x200) |
---|---|
$image->crop(0, 0, 100, 100);
// crop(int $x, int $y, int $width, int $height)
original(600x300) | result(100x100) |
---|---|
ImageResize::POSITION_CENTER;
ImageResize::POSITION_TOP;
ImageResize::POSITION_RIGHT;
ImageResize::POSITION_BOTTOM;
ImageResize::POSITION_LEFT;
ImageResize::POSITION_TOP_LEFT;
ImageResize::POSITION_TOP_RIGHT;
ImageResize::POSITION_BOTTOM_LEFT;
ImageResize::POSITION_BOTTOM_RIGHT;
$image->cropPosition(100, 100);
// cropPosition(int $width, int $height [, int $position = ImageResize::POSITION_CENTER])
original(600x300) | result(100x100) |
---|---|
$image->resizeCover(100, 100);
// resizeCover(int $width, int $height [, int $position = ImageResize::POSITION_CENTER])
original(600x300) | result(100x100) |
---|---|
$image->resizeContain(100, 100);
// resizeContain(int $width, int $height [, int $position = ImageResize::POSITION_CENTER [, int $color = 0x000000]])
original(600x300) | result(100x100) |
---|---|
ImageResize::SIDE_TOP;
ImageResize::SIDE_RIGHT;
ImageResize::SIDE_BOTTOM;
ImageResize::SIDE_LEFT;
ImageResize::SIDE_ALL;
$image->cropEdge(50, ImageResize::SIDE_ALL);
// cropEdge(int $cutLength [, int $side = ImageResize::SIDE_ALL])
original(600x300) | result(500x200) |
---|---|
$image->addBorder(10);
// addBorder(int $borderWidth [, int $side = ImageResize::SIDE_ALL [, int $color = 0x000000]])
original(600x300) | result(620x220) |
---|---|
Fits:
ImageResize::FIT_CANCEL; // cancel if wathermark size grate then $image
ImageResize::FIT_RESIZE; // resize wathermak
ImageResize::FIT_AS_IS; // crop if watermark out of bounds
$watermark = ImageResize::createFromPath($path);
$image->setWatermark($watermark);
// setWatermark(ImageResize $watermark [, int $position = ImageResize::POSITION_BOTTOM_RIGHT [, int $padding = 16 [, int $fit = ImageResize::FIT_AS_IS]]]);
original(600x300) | result(600x300) |
---|---|
$image->change(function(&$resource){
$resource = imagerotate($resource, 90, 0x000000);
});
// change(callable(&$resource) $callback)
original(600x300) | result(300x600) |
---|---|