Skip to content

Latest commit

 

History

History
260 lines (224 loc) · 7.95 KB

README.md

File metadata and controls

260 lines (224 loc) · 7.95 KB

Install

composer require uginroot/image-resize:^1.0

Create

createFromString

$image = ImageResize::createFromString(file_get_content($path));

createFromPath

$image = ImageResize::createFromPath($path);

__constructor

$content = file_get_content($path);
$resource = imagecreatefromstring($content);
$image = new ImageCreate($resource, $content);
$image = new ImageCreate($resource); // $image->resetOrientation() not working

Save

formats

ImageCreate::FORMAT_JPEG;
ImageCreate::FORMAT_PNG;
ImageCreate::FORMAT_WEBP;

save

$image->save($path);
// save(string $path [, int $format = ImageCreate::FORMAT_JPEG [, bool $owerwrite = false [, int $mode = 0666]]])

Optimize image

See this package link

getContent

echo $image->getContent();
// getContent([int $format = ImageCreate::FORMAT_JPEG]);

print

$image->print();
// $image->print([int $format = ImageCreate::FORMAT_JPEG]);

__toString

(string)$image === $image->getContent(ImageCreate::FORMAT_JPEG); // true

copyResource

$image->copyResource();

Info

getWidth

$image->getWidth();

getHeight

$image->getHeight();

resetOrientation

Rotate photo if the set exif orientation tag

$image->resetOrientation();

Change image

scale

$image->scale(50);
// scale(int|float 50)
original(600x300) result(300x150)

resize

$image->resize(100, 100);
// resize(int $width, int $heihht [, bool $increase = true])
original(600x300) result(100x100)

resizeToHeight

$image->resizeToHeight(100);
// resizeToHeight(int $height [, bool $increase = true])
original(600x300) result(100x200)

resizeToWidth

$image->resizeToWidth(100);
// resizeToWidth(int $width [, bool $increase = true])
original(600x300) result(100x50)

resizeToLongSide

$image->resizeToLongSide(100);
// resizeToLongSide(int $side [, $increase = true])
original(600x300) result(100x50)

resizeToShortSide

$image->resizeToShortSide(100);
// resizeToShortSide(int $side [, $increase = true])
original(600x300) result(100x200)

resizeToBestFit

$image->resizeToBestFit(100, 100);
// resizeToBestFit(int $width, int $height [, $increase = true])
original(600x300) result(100x50)

resizeToWorstFit

$image->resizeToWorstFit(100, 100);
// resizeToWorstFit(int $width, int $height [, $increase = true])
original(600x300) result(100x200)

crop

$image->crop(0, 0, 100, 100);
// crop(int $x, int $y, int $width, int $height)
original(600x300) result(100x100)

positions

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;

cropPosition

$image->cropPosition(100, 100);
// cropPosition(int $width, int $height [, int $position = ImageResize::POSITION_CENTER])
original(600x300) result(100x100)

resizeCover

$image->resizeCover(100, 100);
// resizeCover(int $width, int $height [, int $position = ImageResize::POSITION_CENTER])
original(600x300) result(100x100)

resizeContain

$image->resizeContain(100, 100);
// resizeContain(int $width, int $height [, int $position = ImageResize::POSITION_CENTER [, int $color = 0x000000]])
original(600x300) result(100x100)

sides

ImageResize::SIDE_TOP;
ImageResize::SIDE_RIGHT;
ImageResize::SIDE_BOTTOM;
ImageResize::SIDE_LEFT;
ImageResize::SIDE_ALL;

cropEdge

$image->cropEdge(50, ImageResize::SIDE_ALL);
// cropEdge(int $cutLength [, int $side = ImageResize::SIDE_ALL])
original(600x300) result(500x200)

addBorder

$image->addBorder(10);
// addBorder(int $borderWidth [, int $side = ImageResize::SIDE_ALL [, int $color = 0x000000]])
original(600x300) result(620x220)

Watermark

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)

change

$image->change(function(&$resource){
    $resource = imagerotate($resource, 90, 0x000000);
});
// change(callable(&$resource) $callback)
original(600x300) result(300x600)