note 117155 deleted from function.imagecrop by peehaa
| From: | peehaa@php.net | Date: | Thu, 23 Apr 2015 08:42:15 +0000 |
| Subject: | note 117155 deleted from function.imagecrop by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-202330@lists.php.net to get a copy of this message | ||
Note Submitter: marvinmarroquin at gmail dot com
----
<?php
//la forma vieja de hacerlo
function corte($img_fuente,$x,$y,$w,$h,$img_destino)
{
$im_origen = imagecreatefromjpeg($img_fuente);
$im_destino = imagecreatetruecolor($w,$h); //Creo el recurso para la nueva imagen
imagecopy($im_destino, $im_origen, 0,0,$x,$y,$w,$h);
ImageJPEG($im_destino,$img_destino,50); //Exportar imagen a JPG con 50% de calidad
ImageDestroy($im_destino); // La Borro de la Cache
ImageDestroy($im_origen); //La Borro de la Cache
}
//la nueva forma
function corte_crop($img_fuente,$x,$y,$w,$h,$img_destino)
{
$im_origen = imagecreatefromjpeg($img_fuente);//Recurso Origen
$crop = array('x' =>$x , 'y' => $y, 'width' => $w,
'height'=> $h);//Arreglo con coordenadas de corte
$im = imagecrop($im_origen, $crop);//Crop
ImageJPEG($im,$img_destino, 50);//Guardamos la imagen con calidad 50%
ImageDestroy($im_destino); //La Borro de la Cache
ImageDestroy($im_origen); // La Borro de la Cache
}
//La nueva forma es un 50% mas rapida que la vieja forma (Segun mis propios tests)
$w="100";//Ancho
$h="100";//Alto
$x="10";//Posicion X
$y="10";//Posicion Y
$img_fuente="origen.jpg";//imagen Origen debe incluir la ruta y tener los permisos de
lectura en la carpeta
$img_destino="destino.jpg";//imagen destino debe incluir la ruta y tener los permisos de
escritura en la carpeta
//Recorte < php 5.5
corte($img_fuente,$x,$y,$w,$h,$img_destino);
//Recorte > php 5.5
corte_crop($img_fuente,$x,$y,$w,$h,$img_destino);
?>