Well,
It kinda works
but i still got some errors
problem #1: it thinks my folder is a file
problem #1: the new width and height are calculated once
I have no clu how to get it right
I tried a lot
Can someone help me out
by taking the errors out prehaps 🙁
http://clanteo.org/=/multi_upload3/generate_foto_v1.php
<?php
//no timeout
///////////////////////////
@set_time_limit(0);
//variables
//can be changed
///////////////////////////
$max_width = 350;
$max_height = 300;
$dir_upload = "./upload/";
$dir_foto = "./foto/";
//don't change below
//search in directory for excisting files
///////////////////////////
if ($handle = opendir("$dir_upload")) {
while (false !== ($file = readdir($handle))) {
//combine information
///////////////////////////
$foto_source = $dir_upload.$file;
$foto_desteny = $dir_foto.$file;
$size = getimagesize("$foto_source");
$height = $size[1];
$width = $size[0];
//ratio
// -------------> it is only calculated once
///////////////////////////
$img_name = $foto_source;
$new_name = $foto_desteny;
$size=GetImageSize($img_name);
$width_ratio = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
if($width_ratio >=$height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width = ($size[0] / $ratio);
$new_height = ($size[1] / $ratio);
//create image
///////////////////////////
$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
ImageJPEG($thumb,$new_name);
//echo info
///////////////////////////
echo "<br> \n";
echo "$height \n";
echo "<br> \n";
echo "$width \n";
echo "<br> \n";
echo "<br> \n";
echo "$new_height \n";
echo "<br> \n";
echo "$new_width \n";
echo "<br> \n";
echo "<br> \n";
echo "$foto_source";
echo "<br> \n";
echo "$foto_desteny";
}
}
/*
// This will delete all the files in the Upload Folder
///////////////////
ImageDestroy($src_img);
ImageDestroy($thumb);
///////////////////
foreach (glob("upload/*.*") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
unlink($filename);
}
*/
?>