Salve a tutti,
ho un problema nell'effettuare un'operazione di str_replace su una funzione che si occupa di fare la thumb delle immagini. Con str_replace sostituisco eventuali errori nel file immagine (ad esempio uno spazio ... ) e salvo i dati su mysql. Tutto perfetto.
Il problema si presenta quando provo a lavorare con la funzione thumbnail...
in pratica, quando visualizzo l'anteprima dell'articolo vedo soltanto una forma nera...
ecco il codice in questione:
(ah prima di metterci mano con str_replace tutto funzionava perfettamente con le immagini senza errori di sorta ovviamente )
Codice PHP:
<?php
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
//$estensioni = array('jpg','jpeg','gif','GIF','JPG','JPEG');
// open the directory
$dir = @opendir( $pathToImages );
// loop through it, looking for any/all JPG files:
while (false !== ($fname = @readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' || 'GIF' || 'gif' || 'JPEG' || 'JPG' || 'bmp' || 'BMP')
{
// echo "Ho creato miniatura per immagine: {$fname}
";
// load image and get image size
$img = @imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = @imagesx( $img );
$height = @imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = @floor( $height * ( $thumbWidth / $width ) );
// create a new temporary image
$tmp_img = @imagecreatetruecolor( $new_width, $new_height );
//$img = str_replace(" ", "", $img);
// copy and resize old image into new image
@imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
$fname = str_replace(" ", "", $fname);
// save thumbnail into a file
@imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
// close the directory
@closedir( $dir );
}
createThumbs("img/","thumbs/",100);
?>
str_replace devo utilizzarlo con $fname? oppure sto sbagliando ?