note 99774 deleted from function.imagecreatefromjpeg by danbrown
| From: | danbrown@php.net | Date: | Mon, 06 Sep 2010 01:55:02 +0000 |
| Subject: | note 99774 deleted from function.imagecreatefromjpeg by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172326@lists.php.net to get a copy of this message | ||
Note Submitter: condigital at gmail dot com
----
how to compress all JPG images in a directory To a 50% JPG Compressed ..?
This is the Solution.. It is a Excellent output quality
<?
$dir="."; // Ej: images . is the current directory
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file != "." && $file != "..")
{
$file=explode(".",$file);
if(stristr($file[1], 'jpg') == TRUE) // If is a jpg Image
{
$infile= $file[0].".".$file[1];
$img = imagecreatefromjpeg($infile); // create image
if(!is_dir("compressed") )
{mkdir("optimizadas",7777);} // Make Directory '/compressed' to
put the compressed Files there
$cont++;
if (imagejpeg($img,'compressed/'.$infile,50)) //Put the file in to the compressed
dir
{ print "$cont\t $infile\n";}
else
{print "$cont\t $infile ----> Error ..! \n";}
}
}
}
}
if ($cont =='')
{print"\n\n\t\tNot Files Founds...!";}
?>
Please Excuse my English.. I From Colombia :)