<?php
function make_vignette($dir, $pourcentage, $texte='',
$replace='') {
$tab_contenu = array();
if (strlen($dir) > 0 && is_dir($dir)) {
if ($pointeur = opendir($dir)) {
while (false !== ($file = readdir($pointeur))) {
if ($file != "." && $file != "..") {
(is_file($dir . $file) ? $tab_contenu[]
.= "$file" : '');
}
}
closedir($pointeur);
}
if (count($tab_contenu) > 0) {
for($i=0;$i<count($tab_contenu);$i++) {
$path = IMG_PATH.$tab_contenu[$i];
if ($size = @getImageSize($path)) {
$new_file = "mini_" . $tab_contenu[$i]) . $extention;
$dest_path = IMG_MINI_PATH.$new_file;
$dest_width = $size[0] * $pourcentage;
$dest_eight = $size[1] * $pourcentage;
switch ($size[2]) {
case 1:
$src_img = @imageCreateFromGif($path);
break;
case 2:
$src_img = @imageCreateFromJpeg($path);
break;
}
if(strlen($texte) > 0) {
$txt_color = @imagecolorallocate(
$src_img, 0, 0, 0);
imagestring($src_img, 5, 5, 0, $texte, $txt_color);
}
$dst_img = imagecreatetruecolor(
$dest_width, $dest_eight);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0,
$dest_width, $dest_eight, $size[0], $size[1]);
imagejpeg($dst_img, $dest_path, 100);
imagedestroy($dst_img);
}
else{
$dest_path = IMG_MINI_PATH.'nophoto.jpg';
$img = imagecreate(160, 50);
imagecolorallocate ($img, 255, 255, 255);
$txt_color = imagecolorallocate($img, 0, 0, 0);
if(strlen($replace) > 0) {
imagestring($img, 5, 0, 0, $replace, $txt_color);
}
else {
imagestring($img, 4, 0, 0, "Image non disponible",
$txt_color);
}
imagejpeg($img, $dest_path, 100);
}
}
}
}
}
make_vignette("images/", 0.8,
"http://astuces.livres-php.com", "Le support");
?>
|
|