note 38265 deleted from function.imagecopyresampled by pollita
| From: | pollita@php.net | Date: | Sun, 14 Dec 2003 18:51:13 +0000 |
| Subject: | note 38265 deleted from function.imagecopyresampled by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61942@lists.php.net to get a copy of this message | ||
Note Submitter: lito@eordes.com
----
<?
/**
* Función sencilla para a creación de imágenes.
* Solo redimensiona si se supera un máximo de ancho o alto.
**/
function resize_imx ($imx,$max_x=500,$max_y=500) {
list($sx,$sy,$tipo) = getimagesize($imx);
if ($sx > $max_x || $sy > $max_y) {
list($dx,$dy) = $get_image_sizes($sx,$sy,$max_x,$max_y);
switch ($tipo) {
case 1: //GIF
$source_id = imageCreateFromGif($imx);
break;
case 2: //JPEG
$source_id = imageCreateFromJpeg($imx);
break;
case 3: //PNG
$source_id = imageCreateFromPng($imx);
break;
default:
return false;
break;
}
$source_id = imageCreateFromJPEG($imx);
$target_id = imagecreatetruecolor($dx, $dy);
$target_pic = imagecopyresampled($target_id,$source_id,0,0,0,0,$dx,$dy,$sx,$sy);
return imagejpeg($target_id);
} else
return readfile($imx);
}
function get_image_sizes ($ancho,$alto,$max_x,$max_y) {
if ($ancho > $alto) {
if ($ancho > $max_x) {
$n_ancho = $max_x;
$n_alto = ($n_ancho*$alto)/$ancho;
} else {
$n_ancho = $ancho;
$n_alto = ($n_ancho*$alto)/$ancho;
};
settype($n_alto,"integer");
} elseif ($alto > $ancho) {
if ($alto > $max_y) {
$n_alto = $max_y;
$n_ancho = ($n_alto*$ancho)/$alto;
} else {
$n_alto = $alto;
$n_ancho = ($n_alto*$ancho)/$alto;
};
settype($n_ancho,"integer");
} else {
if ($n_ancho > $max_x) {
$n_alto = $max_x;
$n_ancho = $max_y;
} else {
$n_alto = $alto;
$n_ancho = $ancho;
};
};
return array($n_ancho,$n_alto);
}
?>