RE: [PHP-ES] generar thumbail
| From: | LaRanaBudWeisEr | Date: | Fri, 02 May 2003 08:51:02 +0000 |
| Subject: | RE: [PHP-ES] generar thumbail | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-35750@lists.php.net to get a copy of this message | ||
Hola,
Solo mirando en el propio manual de php.net
(http://www.php.net/manual/en/ref.image.php) encuentras esta funcion:
If you ever want to resize a picture (maybe in order to create a thumbnail),
this small function
should help you. It also gives you an idea of how some of the basic image
functions of PHP can be
used.
/* resizeToFile resizes a picture and writes it to the harddisk
*
* $sourcefile = the filename of the picture that is going to be resized
* $dest_x = X-Size of the target picture in pixels
* $dest_y = Y-Size of the target picture in pixels
* $targetfile = The name under which the resized picture will be stored
* $jpegqual = The Compression-Rate that is to be used
*/
function resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile,
$jpegqual)
{
/* Get the dimensions of the source picture */
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
$source_id = imageCreateFromJPEG("$sourcefile");
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($dest_x, $dest_y);
/* Resize the original picture and copy it into the just created image
object. Because of the lack of space I had to wrap the parameters to
several lines. I recommend putting them in one line in order keep your
code clean and readable */
$target_pic=imagecopyresampled($target_id,$source_id,
0,0,0,0,
$dest_x,$dest_y,
$source_x,$source_y);
/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */
imagejpeg ($target_id,"$targetfile",$jpegqual);
return true;
}
Un Saludo.
__________________________________________________
Jose Antonio Rios
EasySQL - http://www.easysql.net
CiberBell - http://www.ciberbell.net
TheWebAnimals, S.L. - http://www.thewebanimals.com
__________________________________________________
-----Original Message-----
From: JASC (RoMaRiO) [mailto:romario11@terra.es]
Sent: viernes, 02 de mayo de 2003 8:56
To: lista@phpes.com
hola gente estoy haciendo un portal de noticias, la idea sería que al hacer
un move_uploaded_file de un .jpg se generase un thumbail de esa imagen para
mostrarla en la noticia
alguna sugerencia??
---------------------------------------------------------------------
Archivo On-line: http://www.phpes.com/
via news: news://news.phpes.com/
Manual PHP en español: http://www.php.net/manual/es/
Para dar de baja la
suscripción, mande un mensaje a:
lista-unsubscribe@phpes.com