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 :

PHP Class resize image


Sujet :

Langage PHP

  1. #1
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut PHP Class resize image
    Bonjour,

    j ai recupérer cette classe qui me semble nickel pour resizer mes images mais quand je l utilise j'ai des messages d'erreur je ne vois pas d'où cela vient

    Merci de votre aide

    script import-test4.php:
    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
     
    // debut resize image
    class Image {
     
        var $file;
        var $image_width;
        var $image_height;
        var $width;
        var $height;
        var $ext;
        var $types = array('','gif','jpeg','png','swf');
        var $quality = 80;
        var $top = 0;
        var $left = 0;
        var $crop = false;
        var $type;
     
        function Image($name='/images/') {
            $this->file = $name;
            $info = getimagesize($name);
            $this->image_width = $info[0];
            $this->image_height = $info[1];
            $this->type = $this->types[$info[2]];
            $info = pathinfo($name);
            $this->dir = $info['dirname'];
            $this->name = str_replace('.'.$info['extension'], '', $info['basename']);
            $this->ext = $info['extension'];
        }
     
        function dir($dir='') {
            if(!$dir) return $this->dir;
            $this->dir = $dir;
        }
     
        function name($name='') {
            if(!$name) return $this->name;
            $this->name = $name;
        }
     
        function width($width='') {
            $this->width = $width;
        }
     
        function height($height='') {
            $this->height = $height;
        }
     
        function resize($percentage=50) {
            if($this->crop) {
                $this->crop = false;
                $this->width = round($this->width*($percentage/100));
                $this->height = round($this->height*($percentage/100));
                $this->image_width = round($this->width/($percentage/100));
                $this->image_height = round($this->height/($percentage/100));
            } else {
                $this->width = round($this->image_width*($percentage/100));
                $this->height = round($this->image_height*($percentage/100));
            }
     
        }
     
        function crop($top=0, $left=0) {
            $this->crop = true;
            $this->top = $top;
            $this->left = $left;
        }
     
        function quality($quality=80) {
            $this->quality = $quality;
        }
     
        function show() {
            $this->save(true);
        }
     
        function save($show=false) {
     
            if($show) @header('Content-Type: image/'.$this->type);
     
            if(!$this->width && !$this->height) {
                $this->width = $this->image_width;
                $this->height = $this->image_height;
            } elseif (is_numeric($this->width) && empty($this->height)) {
                $this->height = round($this->width/($this->image_width/$this->image_height));
            } elseif (is_numeric($this->height) && empty($this->width)) {
                $this->width = round($this->height/($this->image_height/$this->image_width));
            } else {
                if($this->width<=$this->height) {
                    $height = round($this->width/($this->image_width/$this->image_height));
                    if($height!=$this->height) {
                        $percentage = ($this->image_height*100)/$height;
                        $this->image_height = round($this->height*($percentage/100));
                    }
                } else {
                    $width = round($this->height/($this->image_height/$this->image_width));
                    if($width!=$this->width) {
                        $percentage = ($this->image_width*100)/$width;
                        $this->image_width = round($this->width*($percentage/100));
                    }
                }
            }
     
            if($this->crop) {
                $this->image_width = $this->width;
                $this->image_height = $this->height;
            }
     
            if($this->type=='jpeg') $image = imagecreatefromjpeg($this->file);
            if($this->type=='png') $image = imagecreatefrompng($this->file);
            if($this->type=='gif') $image = imagecreatefromgif($this->file);
     
            $new_image = imagecreatetruecolor($this->width, $this->height);
            imagecopyresampled($new_image, $image, 0, 0, $this->top, $this->left, $this->width, $this->height, $this->image_width, $this->image_height);
     
            $name = $show ? null: $this->dir.DIRECTORY_SEPARATOR.$this->name.'.'.$this->ext;
            if($this->type=='jpeg') imagejpeg($new_image, $name, $this->quality);
            if($this->type=='png') imagepng($new_image, $name);
            if($this->type=='gif') imagegif($new_image, $name);
     
            imagedestroy($image); 
            imagedestroy($new_image);
     
        }
     
    }
     
     //Creer un thumb avec 200px de large, la hauteur est automatique.
    $thumb = new Image('/images/'.$filename);
    $thumb->width(700);
    $thumb->save();
     
    // fin resize image
    erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Warning: getimagesize(/images/test21.jpg) [function.getimagesize]: failed to open stream: No such file or directory in W:\var\www\mondossier\import\import-test4.php on line 74
     
    Warning: Division by zero in W:\var\www\mondossier\import\import-test4.php on line 138
     
    Warning: Division by zero in W:\var\www\mondossier\import\import-test4.php on line 138
     
    Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in W:\var\www\prestiglass\import\import-presti4.php on line 166
     
    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in W:\var\www\mondossier\import\import-test4.phpon line 167
     
    Warning: imagedestroy(): supplied argument is not a valid Image resource in W:\var\www\mondossier\import\import-test4.php on line 174
     
    Warning: imagedestroy(): supplied argument is not a valid Image resource in W:\var\www\mondossier\import\import-test4.php on line 175

  2. #2
    Membre Expert
    Avatar de Seb33300
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2007
    Messages
    1 564
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Thaïlande

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 564
    Par défaut
    c'est le chemin d'accès au fichier image que tu lui donne qui n'est pas bon

    failed to open stream: No such file or directory

  3. #3
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut
    Merci seb33300 pourtant
    getimagesize(/images/test21.jpg)
    à l'air correct c est pour cela que ca me semble bizarre

  4. #4
    Membre éclairé
    Inscrit en
    Décembre 2008
    Messages
    319
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 319
    Par défaut
    Oki bon j ai trouvé il fallait mettre le chemin comme ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ('./images/'.$filename);
    Avec le point devant /images

    Merci encore

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

Discussions similaires

  1. [FLASH MX] Problème PHP/Flash insertion image
    Par eyovas dans le forum Flash
    Réponses: 4
    Dernier message: 25/01/2006, 09h09
  2. Classe pour image : besoin de tests,d'avis,d'idées...
    Par Arkham46 dans le forum Access
    Réponses: 56
    Dernier message: 22/01/2006, 23h39
  3. Exporter diagramme de classe vers image
    Par Koko22 dans le forum Rational
    Réponses: 3
    Dernier message: 18/08/2004, 10h42

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