1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
if (isset($_POST['folder'])) // contient "C:\blabla" dans mon exemple
{
$images = @scandir(htmlspecialchars($_POST['folder']));
if ($images === false)
$error = 'Mauvais chemin de dossier.';
else
{
$noimage = true;
foreach($images as $path_image)
{
if ($path_image != '.' && $path_image != '..')
{
$noimage = false;
// manque un move_uploaded_file()
$size = @getimagesize($path_image);
if ($size !== false)
{
$width = 720;
$height = $width * $size[1] / $size[0];
if ($size['mime'] == 'image/jpeg')
{
$img_big = @imagecreatefromjpeg($path_image);
$img_mini = @imagecreatetruecolor($width, $height) or $img_mini = @imagecreate($width, $height);
@imagecopyresized($img_mini, $img_big, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
@imagejpeg($img_mini, $path_image);
}
elseif ($size['mime'] == 'image/png')
{
$img_big = @imagecreatefrompng($path_image);
$img_mini = @imagecreatetruecolor($width, $height) or $img_mini = @imagecreate($width, $height);
@imagecopyresized($img_mini, $img_big, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
@imagepng($img_mini, $path_image);
}
}
}
}
if ($noimage)
$error = 'Pas d\'image trouvée dans le dossier. (Les formats détectés sont JPG/JPEG et PNG)';
else
$error = '<span style="color: green;">Conversion réussie.</span>';
}
}
?> |
Partager