note 117155 added to function.imagecrop
| From: | marvinmarroquin at gmail dot com | Date: | Wed, 22 Apr 2015 22:54:24 +0000 |
| Subject: | note 117155 added to function.imagecrop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202326@lists.php.net to get a copy of this message | ||
<?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);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 190.120.28.115
----
Manual Page -- http://php.net/manual/en/function.imagecrop.php
Edit -- https://master.php.net/note/edit/117155
Del: integrated -- https://master.php.net/note/delete/117155/integrated
Del: useless -- https://master.php.net/note/delete/117155/useless
Del: bad code -- https://master.php.net/note/delete/117155/bad+code
Del: spam -- https://master.php.net/note/delete/117155/spam
Del: non-english -- https://master.php.net/note/delete/117155/non-english
Del: in docs -- https://master.php.net/note/delete/117155/in+docs
Del: other reasons-- https://master.php.net/note/delete/117155
Reject -- https://master.php.net/note/reject/117155
Search -- https://master.php.net/manage/user-notes.php