Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
910 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Compression JPG crade en PHP

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Compression JPG crade en PHP

n°1531996
Dawa
www.shootmeagain.com
Posté le 22-03-2007 à 10:28:05  profilanswer
 

Hello à tous,
 
Sur mon site j'utilise un script qui redimensionne en 800x700 max une image uploadée et qui lui ajoute un petit bandeau en-dessous avec un peu de texte, comme ça par exemple : http://www.shootmeagain.com/photo/ [...] ersk03.jpg
 
Le souci est qu'avec de grandes étendues rouges ou bleues, la compression fait beaucoup de dégâts, alors que la qualité de compression est à 92%...  
 
Exemple :  
 
http://farm1.static.flickr.com/164/415455364_752fb7ce47.jpg -> http://www.shootmeagain.com/photo/1360/_mg_421.jpg  
 
Je vous dépose mon script, est-ce que quelque chose cloche ?
 

Code :
  1. if(is_uploaded_file ($_FILES[$nomtof]['tmp_name']))
  2. {
  3.  $tof=$_FILES[$nomtof]['tmp_name'];
  4.  $newname=$_FILES[$nomtof]['name'];
  5.  $newname = rawurldecode($newname);
  6.  $newname=strtolower($newname);
  7.  $user=strtoupper($_POST['user']);
  8.  $resized=resize($tof,$newname,800,700,"photo/".$_POST['gal']."/",$user);
  9.  $thumb=resize($tof,$newname,130,130, "photo/".$_POST['gal']."/small/" );
  10.  MAJtof($_POST['mode'], $_POST, $bd, $newname);
  11.  $ok=1;
  12. }


 

Code :
  1. <?php
  2. function resize($file, $tofname, $maxWidth, $maxHeight, $path, $user=0)
  3. {
  4.  
  5. ini_set("memory_limit","32M" );
  6. ini_set("max_execution_time","300" );
  7. $prod=$maxWidth*$maxHeight;
  8. //Créé une image à partir de $file
  9. $img = ImageCreateFromJpeg($file);
  10. //Dimensions de l'image
  11. $imgWidth = imagesx($img);
  12. $imgHeight = imagesy($img);
  13. //Facteur largeur/hauteur des dimensions max
  14. $whFact = $maxWidth/$maxHeight;
  15. //Facteur largeur/hauteur de l'original
  16. $imgWhFact = $imgWidth/$imgHeight;
  17. //fixe les dimensions du thumb
  18. if($imgWidth <= $maxWidth && $imgHeight <= $maxHeight)
  19. {
  20. $thumbWidth=$imgWidth;
  21. $thumbHeight=$imgHeight;
  22. }
  23. else
  24. {     
  25. if($imgWidth > $imgHeight)
  26. {
  27.  //Si largeur déterminante
  28.  $thumbWidth  = $maxWidth;
  29.  $thumbHeight = $thumbWidth/$imgWhFact;
  30.  if($thumbHeight>$maxHeight)
  31.  {
  32.   $redimfact=$thumbHeight/$maxHeight;
  33.   $thumbHeight=$maxHeight;
  34.   $thumbWidth=$thumbWidth/$redimfact;
  35.  }
  36. }
  37. else
  38. {
  39.  //Si hauteur déterminante
  40.  $thumbHeight = $maxHeight;
  41.  $thumbWidth = $thumbHeight*$imgWhFact;
  42.  if($thumbWidth>$maxWidth)
  43.  {
  44.   $redimfact=$thumbWidth/$maxWidth;
  45.   $thumbWidth=$maxWidth;
  46.   $thumbHeight=$thumbHeight/$redimfact;
  47.  }
  48. }
  49. }
  50. //Créé le thumb (image réduite)
  51. if($maxWidth==800)
  52. $thumbHeight2=$thumbHeight+20;
  53. else
  54. $thumbHeight2=$thumbHeight;
  55. $imgThumb = ImageCreateTruecolor($thumbWidth, $thumbHeight2);
  56. $white = imagecolorallocate($imgThumb,255,255,255);
  57. $black = imagecolorallocate($imgThumb,0,0,0);
  58. imagefill($imgThumb,0,0,$white);
  59. //Insère l'image de base redimensionnée
  60. ImageCopyResampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
  61. if($maxWidth==800)
  62. {
  63. $postxtx=$thumbWidth-210;
  64. $postxty=$thumbHeight2-5;
  65. $font1="images/GOTHIC.TTF";
  66. imagettftext($imgThumb, 10, 0, 24, $postxty, $black, $font1,"PHOTO BY ".$user);
  67. imagettftext($imgThumb, 10, 0, $postxtx, $postxty, $black, $font1,"WWW.SHOOTMEAGAIN.COM" );
  68. //imagettftext($img, 16, 0, 20, 54, $white, $font1,$bandname2);
  69. }
  70. //Nom du fichier thumb
  71. //list($titretof,$ext,$temp) = explode(".",$file);
  72. $imgThumbName = $path.$tofname;
  73. //Créé le fichier thumb
  74. //  $fp = fopen($imgThumbName, "wb" );
  75. //   fclose($fp);
  76. // fflush($fp);
  77. //Renvoie le thumb créé
  78. ImageJpeg($imgThumb, $imgThumbName,92);
  79. imagedestroy($imgThumb);
  80. imagedestroy($img);
  81. return $imgThumbName;
  82. }
  83. ?>

 
 
Merci beaucoup !


---------------
SHOOT ME AGAIN WEBZINE
mood
Publicité
Posté le 22-03-2007 à 10:28:05  profilanswer
 

n°1532056
Dawa
www.shootmeagain.com
Posté le 22-03-2007 à 11:33:18  profilanswer
 

help please !

n°1532469
Shinuza
This is unexecpected
Posté le 23-03-2007 à 03:51:12  profilanswer
 

Si tu agrandis ta photo, c'est normal que l'interpolation laisse des traces, qui plus est avec un "logiciel" qui n'est pas optimisé pour.


---------------
Mains power can kill, and it will hurt the entire time you’re dying from it.
n°1564278
Dawa
www.shootmeagain.com
Posté le 23-05-2007 à 20:37:57  profilanswer
 

?
 
La photo n'est pas agrandie par le script... Une photo trop grand est rétrécié mais une plus petite est laissée telle quelle !
 
(oups, viens de retomber sur ce topic)

n°1564320
olivthill
Posté le 23-05-2007 à 22:15:57  profilanswer
 

On voit pas bien, c'est la nuit, et en plus, il y a un spot en face qui éblouit.

n°1564393
Master p
My new cock ring :D
Posté le 24-05-2007 à 09:14:00  profilanswer
 

olivthill a écrit :

On voit pas bien, c'est la nuit, et en plus, il y a un spot en face qui éblouit.


[:pingouino]
 
Dans ton exemple, quelle est la dimension de l'image de base ?


---------------
HAHAHA I M USING TEH INTERNET
n°1564397
Free_RideR​_
get up haaaaaaaaa....
Posté le 24-05-2007 à 09:18:14  profilanswer
 

moi je trouve pas ça trop mal. et en png ça donne quoi?


Message édité par Free_RideR_ le 24-05-2007 à 09:18:35

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Compression JPG crade en PHP

 

Sujets relatifs
[PHP/MYSQL] Affichage d'un champ dans une listboxlistes déroulantes l'une HTML l'autre PHP
Probleme lancement programme C sur page PHP[PHP] Fonction include dreamweaver
PHP Et Win2003 ServerLecture d'un fichier XML 1.0 en Php
Bannière à centrer (PHP)Php - retrouver mon image
PHP 4/5 -> Array (pas de liste ?) [Résolu][PHP] Redimensionnement qui écrase les EXIFS d'une image
Plus de sujets relatifs à : Compression JPG crade en PHP


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR