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

Bibliothèques et frameworks PHP Discussion :

[GD] fonction resize recadrage mais probleme de transparence


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 24
    Points : 16
    Points
    16
    Par défaut [GD] fonction resize recadrage mais probleme de transparence
    Bonjour,

    voila ce que j'ai trouvé sur la doc de php : un script qui redimensionne et recadre sans trop perdre l'image de base, l'inconvénient c'est que lorsque l'on redimensionne une image png avec un fond transparent on se retrouve avec une vignette avec un background noir.

    N'étant pas très bon et ayant pourtant chercher à intégrer un fond je n'y suis pas arrivé. Merci pour votre aide

    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
     
    <?php
     
    function makeIcons_MergeCenter($src, $dst, $dstx, $dsty){
     
    //$src = original image location
    //$dst = destination image location
    //$dstx = user defined width of image
    //$dsty = user defined height of image
     
    $allowedExtensions = 'jpg jpeg gif png';
     
    $name = explode(".", $src);
    $currentExtensions = $name[count($name)-1];
    $extensions = explode(" ", $allowedExtensions);
     
    for($i=0; count($extensions)>$i; $i=$i+1){
    if($extensions[$i]==$currentExtensions)
    { $extensionOK=1;
    $fileExtension=$extensions[$i];
    break; }
    }
     
    if($extensionOK){
     
    $size = getImageSize($src);
    $width = $size[0];
    $height = $size[1];
     
    if($width >= $dstx AND $height >= $dsty){
     
    $proportion_X = $width / $dstx;
    $proportion_Y = $height / $dsty;
     
    if($proportion_X > $proportion_Y ){
    $proportion = $proportion_Y;
    }else{
    $proportion = $proportion_X ;
    }
    $target['width'] = $dstx * $proportion;
    $target['height'] = $dsty * $proportion;
     
    $original['diagonal_center'] =
    round(sqrt(($width*$width)+($height*$height))/2);
    $target['diagonal_center'] =
    round(sqrt(($target['width']*$target['width'])+
    ($target['height']*$target['height']))/2);
     
    $crop = round($original['diagonal_center'] - $target['diagonal_center']);
     
    if($proportion_X < $proportion_Y ){
    $target['x'] = 0;
    $target['y'] = round((($height/2)*$crop)/$target['diagonal_center']);
    }else{
    $target['x'] =  round((($width/2)*$crop)/$target['diagonal_center']);
    $target['y'] = 0;
    }
     
    if($fileExtension == "jpg" OR $fileExtension=='jpeg'){
    $from = ImageCreateFromJpeg($src);
    }elseif ($fileExtension == "gif"){
    $from = ImageCreateFromGIF($src);
    }elseif ($fileExtension == 'png'){
     $from = imageCreateFromPNG($src);
    }
     
     
    $new = ImageCreateTrueColor ($dstx,$dsty);
     
    imagecopyresampled ($new,  $from,  0, 0, $target['x'], $target['y'], $dstx, $dsty, $target['width'], $target['height']);
     
     if($fileExtension == "jpg" OR $fileExtension == 'jpeg'){
    imagejpeg($new, $dst, 70);
    }elseif ($fileExtension == "gif"){
    imagegif($new, $dst);
    }elseif ($fileExtension == 'png'){
    imagepng($new, $dst);
    }
    }
    }
    }
     
    $src = "dodo/dodo.png";
    $dst = "dodo/thumbs_dodo4.png";
    $dstx = 150;
    $dsty = 100;
    makeIcons_MergeCenter($src, $dst, $dstx, $dsty)
     
    ?>

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 24
    Points : 16
    Points
    16
    Par défaut trouvé
    Pour ceux que ca intéresse il suffit de rajouter ce code après truecolor

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    imagealphablending($new, false);
    imagesavealpha($new,true);
    $transparent = imagecolorallocatealpha($new, 255, 255, 255, 127);
    imagefilledrectangle($new, 0, 0, $nWidth, $nHeight, $transparent);

    Pour information ce script permet de redimensionner et recadrer votre vignette automatiquement & supporte le format PNG

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

Discussions similaires

  1. Jascript fonction sous IE mais pas sous Netscape ou FF
    Par pierrot10 dans le forum Général JavaScript
    Réponses: 16
    Dernier message: 29/12/2005, 17h02
  2. [FLASH MX2004] Probleme de transparence
    Par Sorento dans le forum Flash
    Réponses: 2
    Dernier message: 15/06/2005, 09h21
  3. Probleme de transparence ... rho encore :/
    Par Clad3 dans le forum OpenGL
    Réponses: 28
    Dernier message: 13/01/2005, 13h17
  4. probleme de transparence avec fog
    Par Daedar dans le forum OpenGL
    Réponses: 10
    Dernier message: 03/05/2004, 08h14
  5. Probleme de transparance
    Par billyboy dans le forum DirectX
    Réponses: 1
    Dernier message: 12/02/2004, 19h40

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