Created
April 24, 2019 04:34
-
-
Save enlacee/fc175011a0aff6bb3e679f57e070aca5 to your computer and use it in GitHub Desktop.
Crear imagen proporcional con Imagick LIBRARY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
// BASIC EXAMPLE (INSPIRATION) | |
// comando usado en LINUX con imagemagick instalado | |
// convert sansung.png -thumbnail 500x500 -background black -gravity center -extent 500x500 end.jpg | |
header('Content-type: image/jpeg'); | |
$image = new Imagick('image.jpg'); | |
$image->setImageBackgroundColor('black'); | |
// If 0 is provided as a width or height parameter, | |
// aspect ratio is maintained | |
$image->thumbnailImage(500, 500,true); | |
$ancho = $image->getImageWidth(); | |
$alto = $image->getImageHeight(); | |
// $image->scaleImage(500, 500, true); | |
$image->setGravity(imagick::GRAVITY_CENTER); | |
$image->extentImage(500,500,0,0); | |
// $image->extentImage(500,500,0,-109.5); | |
// $image->adaptiveResizeImage(500,500); | |
echo $image; | |
*/ | |
header('Content-type: image/jpeg'); | |
$setAncho = 500; | |
$setAlto = 500; | |
$image = new Imagick('image.jpg'); | |
$image->setImageBackgroundColor('black'); | |
// If 0 is provided as a width or height parameter, | |
// aspect ratio is maintained | |
$image->thumbnailImage($setAncho, $setAlto,true); | |
// ancho o alto variable | |
$Currentancho = $image->getImageWidth(); | |
$Currentalto = $image->getImageHeight(); | |
$newX = 0; | |
$newY = 0; | |
if ($Currentancho < $setAncho ) { | |
$newX = (($Currentancho - $setAncho) / 2); | |
} | |
if ($Currentalto < $setAlto ) { | |
$newY = (($Currentalto - $setAlto) / 2); | |
} | |
// echo $newX; | |
// var_dump($newX); | |
// echo "<br>"; | |
// var_dump($newY);EXIT; | |
$image->setGravity(imagick::GRAVITY_CENTER); | |
$image->extentImage($setAncho,$setAlto,$newX,$newY); | |
echo $image; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment