how i can make php that cut part of photos?

Viewed 63

I have a project I'm working on right now... I want to know is there any idea how i can make an app that every time i upload a photo it, with the specific size it cut like the middle part only and puts it on another photo i chose. here is an example : 1 - Upload man photo with white background 2- it takes the middle part of the photo 3 - i upload a garden photo and the man shows there. I just need to know the way to make it. Is there also a way to delete white backgrounds like Chrom key or something?

example enter image description here

enter image description here

enter image description here

1 Answers

Look into ImageMagick

ImageMagick allows you to cut, crop, colorize, etc. For example, here is some sample code showing how to crop a photo:

<?php
function cropImage($imagePath, $startX, $startY, $width, $height) {
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->cropImage($width, $height, $startX, $startY);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}

?>

A brief scan of questions regarding ImageMagick and PHP will be helpful:

https://stackoverflow.com/questions/tagged/imagemagick+php

Resources:

https://phpimagick.com/

ImageMagick options and settings

Using ImageMagick to crop from center with PHP

Related