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

  FORUM HardWare.fr
  Programmation
  PHP

  Comment resizer une photo en PHP ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment resizer une photo en PHP ?

n°238816
angel92
Posté le 03-11-2002 à 14:59:11  profilanswer
 

le client sa photo vers un dossier de mon serveur, mais je ve que cette photo est une taille en pixel particuliere (juste la largeur), comment faire?

mood
Publicité
Posté le 03-11-2002 à 14:59:11  profilanswer
 

n°238840
Schtroumph​eur
bwwwwwaaaaarkkkkkkk!!!!!!
Posté le 03-11-2002 à 16:31:53  profilanswer
 
n°238853
angel92
Posté le 03-11-2002 à 16:55:47  profilanswer
 

schtroumpheur a écrit a écrit :

http://dev.nexen.net/docs/php/anno [...] .php?lien=




 
mais ca ne marche po qu'avec une image create fromg if ?

n°239125
Mirgolth
Posté le 04-11-2002 à 11:19:27  profilanswer
 

Tiens voila une fonction trouvée sur php.net qui fait un resize pour gif, jpg et png.
 

Code :
  1. Improved version of ResizeGif given by tjhunter with Height % Widht.
  2. <?php
  3. /* ResizeGif with (height % width) */
  4. function RatioResizeImg( $image, $newWidth, $newHeight){
  5. //Open the gif file to resize  
  6. eregi(".(.*)$",$image,$regs);
  7. switch($regs[1]){
  8. case "gif": $srcImage = ImageCreateFromGIF( $image ); break;
  9. case "jpg": $srcImage = ImageCreateFromJPEG( $image ); break;
  10. case "png": $srcImage = ImageCreateFromPNG( $image ); break;
  11. default: $srcImage = ImageCreateFromGIF( $image ); break;}
  12. //obtain the original image Height and Width  
  13. $srcWidth = ImageSX( $srcImage );
  14. $srcHeight = ImageSY( $srcImage );
  15. // the follwing portion of code checks to see if  
  16. // the width > height or if width < height  
  17. // if so it adjust accordingly to make sure the image  
  18. // stays smaller then the $newWidth and $newHeight  
  19. $ratioWidth = $srcWidth/$newWidth;
  20. $ratioHeight = $srcHeight/$newHeight;
  21. if( $ratioWidth < $ratioHeight){
  22. $destWidth = $srcWidth/$ratioHeight;
  23. $destHeight = $newHeight;
  24. }else{
  25. $destWidth = $newWidth;
  26. $destHeight = $srcHeight/$ratioWidth;
  27. }
  28. // creating the destination image with the new Width and Height  
  29. $destImage = imagecreate( $destWidth, $destHeight);
  30. //copy the srcImage to the destImage  
  31. ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
  32. //create the gif  
  33. ImageGif( $destImage );
  34. //fre the memory used for the images  
  35. ImageDestroy( $srcImage );
  36. ImageDestroy( $destImage );
  37. }
  38. //save output to a buffer  
  39. ob_start();
  40. //Resize image ( will be stored in the buffer )  
  41. ResizeGif( "/where/image/is/image.gif", "150", "150" );
  42. //copy output buffer to string  
  43. $resizedImage = ob_get_contents();
  44. //clear output buffer that was saved  
  45. ob_end_clean();
  46. //write $resizedImage to Database, file , echo to browser whatever you need to do with it  
  47. ?>

n°239398
angel92
Posté le 04-11-2002 à 19:11:56  profilanswer
 

ok merci, j'essaie de comprendre comment ca marche exactement pi je vou di ce que ca donne

n°239516
angel92
Posté le 04-11-2002 à 21:31:52  profilanswer
 

alors la fo qu'une ame charitable se penche sur mon cas, paske j'ai rien capté au script !!!

n°239540
sielfried
Posté le 04-11-2002 à 21:40:43  profilanswer
 

Ben sans avoir lu en détail le corps de la fonction, apparemment suffit de l'appeler avec le chemin du gif, la largeur voulue, la hauteur voulue, et ça te l'affiche resizee.
 
Ou un truc dans le genre.


---------------
StarCraft Professional Gaming Database | [Ze Topic] Starcraft/BroodWar
n°239585
angel92
Posté le 04-11-2002 à 22:14:34  profilanswer
 

mais le prob c k'il me du undifined function pour reziseGif

n°239653
Mirgolth
Posté le 05-11-2002 à 08:19:12  profilanswer
 

angel92 a écrit a écrit :

mais le prob c k'il me du undifined function pour reziseGif




 
En effet, il te manque ça ( toujours dispo sur http://www.php.net/manual/en/ref.image.php ) :
 

Code :
  1. <?php
  2. function ResizeGif( $image, $newWidth, $newHeight){
  3. //Open the gif file to resize  
  4. $srcImage = ImageCreateFromGif( $image );
  5. //obtain the original image Height and Width  
  6. $srcWidth  = ImageSX( $srcImage );
  7. $srcHeight = ImageSY( $srcImage );
  8. // the follwing portion of code checks to see if  
  9. // the width > height or if width < height  
  10. // if so it adjust accordingly to make sure the image  
  11. // stays smaller then the $newWidth and $newHeight  
  12. if( $srcWidth < $srcHeight ){
  13. $destWidth  = $newWidth * $srcWidth/$srcHeight;
  14. $destHeight = $newHeight;
  15. }else{
  16. $destWidth  = $newWidth;
  17. $destHeight = $newHeight * $srcHeight/$srcWidth;
  18. }
  19. // creating the destination image with the new Width and Height  
  20. $destImage = imagecreate( $destWidth, $destHeight);
  21. //copy the srcImage to the destImage  
  22. ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
  23. //create the gif  
  24. ImageGif( $destImage );
  25. //fre the memory used for the images  
  26. ImageDestroy( $srcImage  );
  27. ImageDestroy( $destImage );
  28. }
  29. //save output to a buffer  
  30. ob_start();
  31. //Resize image  ( will be stored in the buffer )  
  32. ResizeGif( "/where/image/is/image.gif", "150", "150" );
  33. //copy output buffer to string  
  34. $resizedImage = ob_get_contents();
  35. //clear output buffer that was saved  
  36. ob_end_clean();
  37. //write $resizedImage to Database, file , echo to browser whatever you need to do with it

n°239769
angel92
Posté le 05-11-2002 à 12:41:49  profilanswer
 

lol, faudrais que je m'instaresse d eplus pres a ce site.
merci


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

  Comment resizer une photo en PHP ?

 

Sujets relatifs
[PHP]{newbie neuneu} bricoler une table[PHP] A propos de la librairie GD
Yahoo! adopte le langage de script PHP[PHP] Probleme avec les fonctions
[PHP - Apache] Les variables ne passent pas...Mettre du texte à la ligne d'une photo
[PHP] Décomposition d'un nombre par 3 et 4PHP?
[PHP] Extraire les deux premiers caractères d'une chaîne - RESOLUODBC / Linux / Php
Plus de sujets relatifs à : Comment resizer une photo en PHP ?


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