$resized_img = imagecreatetruecolor($newwidth,$newheight);
$white = imagecolorallocate($resized_img, 255, 255, 255);
$grey = imagecolorallocate($resized_img, 128, 128, 128);
$black = imagecolorallocate($resized_img, 0, 0, 0);
imagefilledrectangle($resized_img, 0, 0, 399, 29, $white);
$text = 'Test...';
$font = 'arial.ttf';
imagettftext($resized_img, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($resized_img, 20, 0, 10, 20, $black, $font, $text);
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//save image
Imagepng ($resized_img,"$path_thumbs/$rand_name-mini.png");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);
mais sa ne marche pas
Code : Tout sélectionner
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img2 = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img2 = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img2 = imagecreatefromgif($file_tmp);
}
list($width, $height) = getimagesize($file_tmp);
$imgratio2=$width/$height;
if ($imgratio2>1){
$newwidth2 = $ThumbWidth2;
$newheight2 = $ThumbWidth2/$imgratio2;
}else{
$newheight2 = $ThumbWidth2;
$newwidth2 = $ThumbWidth2*$imgratio2;
}
$resized_img2 = imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresized($resized_img2, $new_img2, 0, 0, 0, 0, $newwidth2,
$newheight2, $width, $height);
Imagejpeg ($resized_img2,"$path_big/$rand_name.$file_ext");
ImageDestroy ($resized_img2);
ImageDestroy ($new_img2);//get the new width variable.///////////////////////
$ThumbWidth = $img_thumb_width;
//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;
}
$resized_img = imagecreatetruecolor($newwidth,$newheight);
/***************************************************/
/* création de la légende : texte en blanc */
/***************************************************/
$blanc = imagecolorallocate($resized_img,255,255,255); //couleur blanche
$string = "test test test test";
$write_h = $height - imagefontheight(3) - 1; //hauteur
/* centrage -> on récupère $n_largeur la largeur */
/* de la vignette, on lui retire la largeur de la */
/* police multipliée par le nombre de caractères */
/* puis on divise le résultat par 2 pour centrer */
$write_w = ($width - strlen($string) * imagefontwidth(3))/2;
imagestring($resized_img, 3, $write_w, $write_h, $string, $blanc); //on écrit la légende
/***************************************************/
/* ouverture du fichier */
/***************************************************/
$source = imagecreatefromjpeg($file_tmp);
/***************************************************/
/* réduction, rééchantillonage et copie de l'image */
/* originale */
/* on recopie l'image à partir du point de */
/* coordonnées 1,1 pour laisser un cadre noir */
/***************************************************/
imagecopyresampled($resized_img,$source, 1,1, 0,0, $newwidth, $newheight, $width, $height);
//save image
Imagepng ($resized_img,"$path_thumbs/$rand_name-mini.png");
ImageDestroy ($resized_img);
ImageDestroy ($new_img);//save image
Imagepng ($resized_img,"$path_thumbs/$rand_name-mini.png");
penser à le passer en
//save image
Imagepng ($resized_img,$path_thumbs."/".$rand_name."-mini.png");
Ensuite pour ton problème, je te conseille dans un premier temps de mettre un htaccess sur ton site avec la ligne Code : Tout sélectionner
php_flag display_errors On//keep image type///////////////////////////////
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img2 = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$new_img2 = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$new_img2 = imagecreatefromgif($file_tmp);
}
//list width and height and keep height ratio.//////////////////////
list($width, $height) = getimagesize($file_tmp);
$imgratio2=$width/$height;
if ($imgratio2>1){
$newwidth2 = $ThumbWidth2;
$newheight2 = $ThumbWidth2/$imgratio2;
}else{
$newheight2 = $ThumbWidth2;
$newwidth2 = $ThumbWidth2*$imgratio2;
}
$infos = GetImageSize ($file_tmp);
//On stock les infos
$width = $infos[0];
$high = $infos[1];
$type = $infos[2];
//On crée notre nouvelle image:
$im = ImageCreate ($width, $high + 10); //On ajoute 10 pixels en bas pour ajouter les commentaires
$couleur_fond = ImageColorAllocate ($im, 0, 0, 0); //On stock la couleur noire pour le fond
ImagePng ($im); //Faire un if en fonction du type réccupéré pour mettre les bonne fonctions. Pour l'exemple on prendra le png
//On copie l'image uploadé dans notre nouvelle
ImageCopy ($im, $file_tmp, 0, 0, 0, 0, $width, $high);
//On insert la phrase de l'user
$blanc = ImageColorAllocate ($im, 255, 255, 255);
$texte = "toto toto toto";
ImageString($im, 2, $high+4, $width-18, $texte, $blanc);
//Et on crée l'image
ImagePng ($im);
//Et on crée l'image
Imagejpeg ($im,"$path_big/$rand_name.$file_ext");
mais j'obtiens encore une image noir .... Nom du fichier:
create_image.php
<?php
$nom_image = ""; // le nom de votre image avec l'extension jpeg
$texte = "http://www.phpsources.org/"; // Le texte que vous désirez écrire sur l'image
header ("Content-type: image/jpeg");
$image = imagecreatefromjpeg($nom_image);
$blanc = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 5, 150, 150,$texte, $blanc);
imagejpeg($image);
?>
<!--
C'est ici qu'on incorpore l'image. Donc ouvrez une page et placez la balise ci dessous
C'est donc la balise HTML classique IMG
-->
<img src="create_image.php">