par
stefane321 » 15 oct. 2009, 23:43
Bonjour,
J'ai besoin de redimensionner 3000 images
J'ai donc fait un bout de code qui marche mais pour une raison inconnu il n'en fait que environs 200 et le script arrete
jai pensé augmenté les limite de php.ini mais sa na rien changé
Voici mon code:
function resize_images($max_width, $max_height, $img_path)
{
$maxwidth = $max_width;
$maxheight = $max_height;
$imgpath = $img_path;
$imagehw = GetImageSize("$imgpath");
$imagewidth = $imagehw[0];
$imageheight = $imagehw[1];
if($imagewidth >= $imageheight)
{
if ($imagewidth > $maxwidth)
{
$imageprop = ($maxwidth*100)/$imagewidth;
$imagevsize = ($imageheight*$imageprop)/100 ;
$r_width = $maxwidth;
$r_height = ceil($imagevsize);
}
else
{
$r_width = $imagewidth;
$r_height = $imageheight;
}
$returned = array("$r_width", "$r_height", "$imagewidth", "$imageheight");
}
else
{
if ($imageheight > $maxheight)
{
$imageprop = ($maxheight*100)/$imageheight;
$imagevsize = ($imagewidth*$imageprop)/100 ;
$r_width = ceil($imagevsize);
$r_height = $maxheight;
}
else
{
$r_width = $imagewidth;
$r_height = $imageheight;
}
$returned = array("$r_width", "$r_height", "$imagewidth", "$imageheight");
}
return $returned;
}
function redimensionner($source, $destination)
{
//--------------------------------------------------------------------
$size = getimagesize("/home/content/j/m/a/jmartinacn/html/".$source) or die("getimagesize erreur 35");
$newwidth=resize_images(50, 50, $source) or die("rezine width erreur");
$src_img = imagecreatefromjpeg($source) or die("imagecreatefromjpg erreur");
$dst_img = imagecreatetruecolor ($newwidth[0],$newwidth[1]) or die("createtruecolor erreur 40");
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $newwidth[0],$newwidth[1], $size[0], $size[1]) or die("imagecopyresampled erreur"); // la fonction qui redimensionne les photos
imagejpeg($dst_img, $destination, 60) or die("imagejpg erreur179");
imagedestroy($src_img) or die("destroy src_img erreur");
imagedestroy($dst_img) or die("destroy dest_img erreur");
//-----------------------------------------------------------------------------------------
}
$rep_dest = "pictures/listings7/";
$rep_source = "listings/";
mysql_connect("***","***","***") or die("Impossible de connecter la bd");
$base=mysql_select_db("nospac") or die("erreur de DB");
$table=mysql_query('select id, ad_id, picture from class_ads_pictures') or die("Impossible d'ouvrir la table");
while ($row=mysql_fetch_array($table))
{
if (file_exists("listings/".$row["picture"]."") && filesize("listings/".$row["picture"]."")>0) {
$path_parts = pathinfo("listings/".$row["picture"]."");
if($path_parts['extension']=="jpg")
{
echo "".$row["id"]." = listings/".$row["picture"]."<br>";
redimensionner("listings/".$row["picture"]."", "pictures/listings7/".$row["ad_id"]."_112.jpg");
}
}
}
Pouvez-vous m'aider svp?
Merci!
Bonjour,
J'ai besoin de redimensionner 3000 images
J'ai donc fait un bout de code qui marche mais pour une raison inconnu il n'en fait que environs 200 et le script arrete
jai pensé augmenté les limite de php.ini mais sa na rien changé
Voici mon code:
[php]function resize_images($max_width, $max_height, $img_path)
{
$maxwidth = $max_width;
$maxheight = $max_height;
$imgpath = $img_path;
$imagehw = GetImageSize("$imgpath");
$imagewidth = $imagehw[0];
$imageheight = $imagehw[1];
if($imagewidth >= $imageheight)
{
if ($imagewidth > $maxwidth)
{
$imageprop = ($maxwidth*100)/$imagewidth;
$imagevsize = ($imageheight*$imageprop)/100 ;
$r_width = $maxwidth;
$r_height = ceil($imagevsize);
}
else
{
$r_width = $imagewidth;
$r_height = $imageheight;
}
$returned = array("$r_width", "$r_height", "$imagewidth", "$imageheight");
}
else
{
if ($imageheight > $maxheight)
{
$imageprop = ($maxheight*100)/$imageheight;
$imagevsize = ($imagewidth*$imageprop)/100 ;
$r_width = ceil($imagevsize);
$r_height = $maxheight;
}
else
{
$r_width = $imagewidth;
$r_height = $imageheight;
}
$returned = array("$r_width", "$r_height", "$imagewidth", "$imageheight");
}
return $returned;
}
function redimensionner($source, $destination)
{
//--------------------------------------------------------------------
$size = getimagesize("/home/content/j/m/a/jmartinacn/html/".$source) or die("getimagesize erreur 35");
$newwidth=resize_images(50, 50, $source) or die("rezine width erreur");
$src_img = imagecreatefromjpeg($source) or die("imagecreatefromjpg erreur");
$dst_img = imagecreatetruecolor ($newwidth[0],$newwidth[1]) or die("createtruecolor erreur 40");
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $newwidth[0],$newwidth[1], $size[0], $size[1]) or die("imagecopyresampled erreur"); // la fonction qui redimensionne les photos
imagejpeg($dst_img, $destination, 60) or die("imagejpg erreur179");
imagedestroy($src_img) or die("destroy src_img erreur");
imagedestroy($dst_img) or die("destroy dest_img erreur");
//-----------------------------------------------------------------------------------------
}
$rep_dest = "pictures/listings7/";
$rep_source = "listings/";
mysql_connect("***","***","***") or die("Impossible de connecter la bd");
$base=mysql_select_db("nospac") or die("erreur de DB");
$table=mysql_query('select id, ad_id, picture from class_ads_pictures') or die("Impossible d'ouvrir la table");
while ($row=mysql_fetch_array($table))
{
if (file_exists("listings/".$row["picture"]."") && filesize("listings/".$row["picture"]."")>0) {
$path_parts = pathinfo("listings/".$row["picture"]."");
if($path_parts['extension']=="jpg")
{
echo "".$row["id"]." = listings/".$row["picture"]."<br>";
redimensionner("listings/".$row["picture"]."", "pictures/listings7/".$row["ad_id"]."_112.jpg");
}
}
}[/php]
Pouvez-vous m'aider svp?
Merci!