8796 sujets

Développement web côté serveur, CMS

Bonjour,

J'utilise un script pour redimensionner les photos qui marche bien habituellement sauf qu'avec uploadify (utilitaire jquery de téléchargement) les photos ne sont que des rectangles noirs bien redimensionnés. La différence c'est que le script de redimensionnement est sur une page à part, contrairement au cas où ca marchait bien.


Voici mon code dans la page uploadify.php:

<?php


$path_thumbs = "../images";

//the new width of the resized image.
$img_thumb_width = 140; // in pixel

//if the for has submitted
if (!empty($_FILES)) {

$file_type = $_FILES['Filedata']['type'];
$file_name = $_FILES['Filedata']['name'];
$file_size = $_FILES['Filedata']['size'];
$file_tmp = $_FILES['Filedata']['tmp_name'];


//get the new width variable.
$ThumbWidth = $img_thumb_width;

// Création de la vignette
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg")
{
$new_img = imagecreatefromjpeg($file_tmp);
}
elseif($file_type == "image/x-png" || $file_type == "image/png")
{
$new_img = imagecreatefrompng($file_tmp);
}
elseif($file_type == "image/gif")
{
$new_img = imagecreatefromgif($file_tmp);
}

//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1)
{
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
}
else
{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$imgratio;
}

//function for resize image
if (function_exists(imagecreatetruecolor))
{
$resized_img = imagecreatetruecolor($newwidth,$newheight);
}
else
{
die("Error: Please make sure you have GD library ver 2+");
}

imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
echo "1";

//save image
ImageJpeg ($resized_img,"$path_thumbs/$file_name",100);
ImageDestroy ($resized_img);
ImageDestroy ($new_img);

}
}
?>

sur la page d'origine qui appelle le script j'ai :

<script type="text/javascript" src="uploadify/example/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="uploadify/example/scripts/swfobject.js"></script>
<script type="text/javascript" src="uploadify/example/scripts/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#uploadify").uploadify({
		'uploader'       : 'uploadify/example/scripts/uploadify.swf',
		[#red]'script'         : 'uploadify.php',[/#]
		'cancelImg'      : 'uploadify/example/cancel.png',
		'queueID'        : 'fileQueue',
		'fileDesc'		 : 'image en .jpg',
		'buttonText'     : 'Parcourir...',
		'fileExt'        : '*.jpg',
		'sizeLimit'      : '4194304',
		'queueSizeLimit' : '2',
		'auto'           : false,
		'multi'          : true
		$idEvent;?>'}
	});
});
</script>




Merci de vos réponses,

dlg
Modifié par dlg74 (31 Oct 2010 - 17:37)