Answer the question
In order to leave comments, you need to log in
How to prepare an image for Instagramram?
I have a wonderful
function SquareImage($imgSrc, $imgDes, $thumbSize = 1000){
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
if (file_exists($imgSrc)) {
unlink($imgSrc);
}
imagejpeg($thumb, $imgDes, 100);
@imagedestroy($myImage);
@imagedestroy($thumb);
}
SquareImage();
Answer the question
In order to leave comments, you need to log in
Adding margins (white/black/grey, etc.) is one option.
Another option is to first enlarge the image proportionally so that the dimensions are at least 400.
And then crop it to a square.
I would add a size check and an increase (if necessary) immediately after the line:
list($width, $height) = getimagesize($imgSrc);
The image will lose a little quality (or maybe a lot - if one of the sizes is very small),
but there will be no extra margins.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question