IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Redimensionnement d'image et changement du texte


Sujet :

Langage PHP

  1. #1
    TrX
    TrX est déconnecté
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7
    Points : 7
    Points
    7
    Par défaut Redimensionnement d'image et changement du texte
    Bonjour a tous
    voici une fonction qui selectionne les url d'images des message de mon forum afin de les redimensionner si elles sont trop grandes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
     function prevpost($txt, $pmess, $i, $bol) {
     if (preg_match('/\[img=/', $txt)) {
     
     $txt = strstr($txt, '[img=');
    $pos = strpos($txt, ']');
    $img[$i]=substr($txt, 5, $pos-5);                
    list($width, $height) = getimagesize($img[$i]); 
    if ($width>665){
    $extension = substr( $img[$i], -3 );
    $extension = strtolower( $extension );
    switch ( $extension ) {
        case "jpg":
        case "peg":
            $img_src_resource = imagecreatefromjpeg( $img[$i] );
            break;
        case "gif":
            $img_src_resource = imagecreatefromgif( $img[$i]);
            break;
        case "png":
            $img_src_resource = imagecreatefrompng( $img[$i] );
            break;
        case "bmp":
            $img_src_resource = imagecreatefrombmp( $img[$i] );
            break;
        default:
            echo "L'image n'est pas dans un format reconnu. Extensions autorisées : jpg/jpeg, gif, png, bmp";
            break;
    }
     
     
    $new_width = 665;  
    $new_height = 665/$width * $height;
     $img_dst_resource = imagecreatetruecolor($new_width, $new_height);
    //$imge = imagecreatefromjpeg($img[$i]);  
    imagecopyresampled( $img_dst_resource, $img_src_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);  
      if ($bol=="1") {  
          if ($dh = opendir('pix/img')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
           switch ( $extension ) {
        case "jpg":
        case "peg":
           $img_dst_chemin="pix/img/img$k.jpg";
     imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
            break;
        case "gif":
             $img_dst_chemin="pix/img/img$k.gif";
     imagegif( $img_dst_resource, $img_dst_chemin, 100 );
          break;
        case "png":
             $img_dst_chemin="pix/img/img$k.png";
     imagepng( $img_dst_resource, $img_dst_chemin, 100 );
          break;
       case "bmp":
            $img_dst_chemin="pix/img/img$k.bmp";
     imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
           break;
       }
    } else {
    if ($dh = opendir('pix/temp')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
           switch ( $extension ) {
        case "jpg":
        case "peg":
           $img_dst_chemin="pix/temp/img$i.jpg";
     imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
            break;
        case "gif":
             $img_dst_chemin="pix/temp/img$i.gif";
     imagegif( $img_dst_resource, $img_dst_chemin, 100 );
          break;
        case "png":
             $img_dst_chemin="pix/temp/img$i.png";
     imagepng( $img_dst_resource, $img_dst_chemin, 100 );
          break;
       case "bmp":
            $img_dst_chemin="pix/temp/img$k.bmp";
     imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
           break;
       }
    }
    $pmess = str_replace($img[$i], $img_dst_chemin, $pmess);
     
    }
    if ($bol==1 && width<=665) {
    if ($dh = opendir('pix/img')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
              switch ( $extension ) {
        case "jpg":
        case "peg":
             $img_dst_chemin="pix/temp/img$k.jpg";
    copy($img[$i], $img_dst_chemin);
            break;
        case "gif":
            $img_dst_chemin="pix/temp/img$k.gif";
     copy($img[$i], $img_dst_chemin);
            break;
        case "png":
            $img_dst_chemin="pix/temp/img$k.png";
    copy($img[$i], $img_dst_chemin);
            break;
        case "bmp":
           $img_dst_chemin="pix/temp/img$k.bmp";
     copy($img[$i], $img_dst_chemin);
            break;
     
    }
    $pomess = str_replace($img[$i], $img_dst_chemin, $pmess);
     
     }
              $txt=substr($txt, $pos+1);  
     
    $i++;
    prevpost($txt, $pmess, $i, $bol);
    }
     
     
    }
    je voudrai dans un premier temps previsaliser le message avec les image redimensionnées pour ce faire je veux utiliser la fonction comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    echo '<div class=inputbox><font size = "2" face="verdana" color = "#CA0000">'.$pseudo.'</font><br>
     <font size = "2" face="verdana" color = "#666666">'.prevpost($postmess ,$postmess , 0, 0).'</font></div>';
    et donc je voudrai savoir pourquoi ce n'est pas applicable comme ça
    Merci

  2. #2
    Membre éclairé Avatar de |PaRa-BoL
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    738
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 738
    Points : 876
    Points
    876
    Par défaut
    Ta fonction ne retourne aucun résultat

  3. #3
    TrX
    TrX est déconnecté
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    admetons que je mette
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
     function prevpost($txt, $pmess, $i, $bol) {
     if (preg_match('/\[img=/', $txt)) {
     
     $txt = strstr($txt, '[img=');
    $pos = strpos($txt, ']');
    $img[$i]=substr($txt, 5, $pos-5);                
    list($width, $height) = getimagesize($img[$i]); 
    if ($width>665){
    $extension = substr( $img[$i], -3 );
    $extension = strtolower( $extension );
    switch ( $extension ) {
        case "jpg":
        case "peg":
            $img_src_resource = imagecreatefromjpeg( $img[$i] );
            break;
        case "gif":
            $img_src_resource = imagecreatefromgif( $img[$i]);
            break;
        case "png":
            $img_src_resource = imagecreatefrompng( $img[$i] );
            break;
        case "bmp":
            $img_src_resource = imagecreatefrombmp( $img[$i] );
            break;
        default:
            echo "L'image n'est pas dans un format reconnu. Extensions autorisées : jpg/jpeg, gif, png, bmp";
            break;
    }
     
     
    $new_width = 665;  
    $new_height = 665/$width * $height;
     $img_dst_resource = imagecreatetruecolor($new_width, $new_height);
    //$imge = imagecreatefromjpeg($img[$i]);  
    imagecopyresampled( $img_dst_resource, $img_src_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);  
      if ($bol=="1") {  
          if ($dh = opendir('pix/img')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
           switch ( $extension ) {
        case "jpg":
        case "peg":
           $img_dst_chemin="pix/img/img$k.jpg";
     imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
            break;
        case "gif":
             $img_dst_chemin="pix/img/img$k.gif";
     imagegif( $img_dst_resource, $img_dst_chemin, 100 );
          break;
        case "png":
             $img_dst_chemin="pix/img/img$k.png";
     imagepng( $img_dst_resource, $img_dst_chemin, 100 );
          break;
       case "bmp":
            $img_dst_chemin="pix/img/img$k.bmp";
     imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
           break;
       }
    } else {
    if ($dh = opendir('pix/temp')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
           switch ( $extension ) {
        case "jpg":
        case "peg":
           $img_dst_chemin="pix/temp/img$i.jpg";
     imagejpeg( $img_dst_resource, $img_dst_chemin, 100 );
            break;
        case "gif":
             $img_dst_chemin="pix/temp/img$i.gif";
     imagegif( $img_dst_resource, $img_dst_chemin, 100 );
          break;
        case "png":
             $img_dst_chemin="pix/temp/img$i.png";
     imagepng( $img_dst_resource, $img_dst_chemin, 100 );
          break;
       case "bmp":
            $img_dst_chemin="pix/temp/img$k.bmp";
     imagebmp( $img_dst_resource, $img_dst_chemin, 100 );
           break;
       }
    }
    $pmess = str_replace($img[$i], $img_dst_chemin, $pmess);
     
    }
    if ($bol==1 && width<=665) {
    if ($dh = opendir('pix/img')) {
          $k=0;
           while (($filea = readdir($dh)) !== false) {
             if ($filea!= "."  && $filea!= ".." && $filea!= "Thumbs.db"){
              $k++;
              }
              }
              }
              switch ( $extension ) {
        case "jpg":
        case "peg":
             $img_dst_chemin="pix/temp/img$k.jpg";
    copy($img[$i], $img_dst_chemin);
            break;
        case "gif":
            $img_dst_chemin="pix/temp/img$k.gif";
     copy($img[$i], $img_dst_chemin);
            break;
        case "png":
            $img_dst_chemin="pix/temp/img$k.png";
    copy($img[$i], $img_dst_chemin);
            break;
        case "bmp":
           $img_dst_chemin="pix/temp/img$k.bmp";
     copy($img[$i], $img_dst_chemin);
            break;
     
    }
    $pomess = str_replace($img[$i], $img_dst_chemin, $pmess);
     
     }
              $txt=substr($txt, $pos+1);  
     
    $i++;
    prevpost($txt, $pmess, $i, $bol);
    } else {
    return $pmess;  //<-
    }
    }
    c'est pareil je me demande si c pas les deux même arguments dans la function apelée dans le echo qui foire

  4. #4
    TrX
    TrX est déconnecté
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    merci |PaRa-BoL c'est en partie la solution mais la récursivité de la fonction me turlupine un peu (j'ai reposté plus clairement)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. changement automatique d'une image et d'un texte
    Par apfwl.87 dans le forum Word
    Réponses: 1
    Dernier message: 28/05/2009, 11h49
  2. redimensionner une image dans de texte RTF (RichEdit)
    Par byhack0 dans le forum Autres outils décisionnels
    Réponses: 1
    Dernier message: 29/05/2008, 09h23
  3. Réponses: 4
    Dernier message: 30/10/2006, 00h53
  4. [réglé][JSP - Resin] Redimensionnement d'images ...
    Par Claude Pelletier dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 24/03/2005, 18h47
  5. [MX2004] redimensionner une image lors du chargement
    Par ouinouin dans le forum Flash
    Réponses: 8
    Dernier message: 18/02/2004, 18h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo