*bump* (eller nått...)
Jag använder följande kod för att skapa två olika miniatyrer (från en mapp på servern), samt för att flytta originalbilden, men något blir "knas" med vissa bilder.
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
$dir = opendir( $pathToImages );
while (false !== ($fname = readdir( $dir ))) {
$info = pathinfo($pathToImages . $fname);
if ( strtolower($info['extension']) == 'jpg')
{
if (stristr($info['filename'], "normal_") === FALSE && stristr($info['filename'], "thumb_") === FALSE)
{
echo "Skapar miniatyr för <b>{$fname}</b><br />";
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
$randFilename = uniqid("img_");
$newFilename = $randFilename.".".$info['extension'];
imagejpeg( $tmp_img, "{$pathToThumbs}{$newFilename}", 60 );
copy("{$pathToImages}{$fname}", "{$newFilename}");
list($width, $height) = getimagesize("{$pathToImages}{$fname}");
$storlek = filesize("{$pathToImages}{$fname}");
$medlem = 1;
$kategori = 5;
$kommentar = sqlesc($_POST["kommentar"]);
$in = array("-", "_", "xxx", "cover", ".jpg", "xxx", "dvd");
$out = array(" ", " ", "", "", "", "", "");
$title = str_replace($in,$out,"" .strtolower("{$fname}"). "");
mysql_query("INSERT INTO bilder (datum, anvandare, kategori, filnamn, titel, kommentar, bredd, hojd, storlek)
VALUES(NOW(), $medlem, $kategori, '$newFilename', '$title', $kommentar, $width, $height, $storlek)")
or sqlerr(__FILE__, __LINE__);
}
}
}
closedir( $dir );
}
createThumbs("/uploads/","mini/",330);
createThumbs("/uploads/","mellan/",690);
Det som händer, är att flera av de minsta bilderna (bredd 330), inte skapas alls.
Vad kan vara fel?
