bebop Posted November 3, 2009 Share Posted November 3, 2009 Hello, I hope you can help me because this piece of script is driving me mad. This script reads a folder, should select files that are of image format - JPG and variants-of-extension, and re-samples & saves them into another folder for thumbnail view. The problem with it is that it works for some jpeg files but not others - indiscriminately! So I have no clue what makes it work with some and not others (in the same folder!!). Then, again - sometimes, if I change a file extension from say "JPEG" to "JPG" and re-run the script, it works on that file (and keeps ignoring the others). If it's of any relevance, all the files come from the same source - the same digital camera. Any clue why? Also one more question if I may, do I need some sort of buffering - sometimes the folder might contain 50 pics (or more) that the script (if working properly) would have to work on... Thank you so much in advance for your kind help! <?php require_once "database_connection_file.php"; $resampleDir = $_POST['resampleDir']; $path = $_POST['path']; $table = $_POST['table']; if ($handle = opendir($resampleDir)) { [b] while (false !== ($file = readdir($handle))) { $exts = split("[/\\.]", $file); $n = count($exts)-1; $exts = $exts[$n]; if ($exts == "jpg" || $exts == "JPG" || $exts == "JPEG" || $exts == "jpeg") {[/b] $pathToFile = "$resampleDir" . "/"; $percent = 0.165; // resampling down from original fixed size; list($width, $height) = getimagesize($pathToFile . $file); $new_width = $width * $percent; $new_height = $height * $percent; $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($pathToFile . $file); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); if (!file_exists($path . $file)) { $dbPicPath = $path . $file; $sql = "INSERT INTO $table (`index`, `name`, `scale`, `rotate`) VALUES (NULL, '$file', NULL, '0')"; $result = mysql_query($sql, $link) or die(mysql_error()); imagejpeg($image_p, $path . $file, 100); echo "&resampling=" . "yes"; } else { echo "&resampling=" . "no"; } } } closedir($handle); } mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/180174-file-extension-image-resampling/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.