bonjour,
je me permet de poster ce message car j'ai un petit souci concernant la mise en ligne de mon portfolio.
j'ai suivi le tuto de grafikart sur la réalisation d'un portfolio en 5 étapes. le projet à parfaitement marché en local mais lorsque je veux le mettre en ligne, le redimensionnement d'image ne se fait pas normalement. voici le message d'erreur que j'ai :

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'home/stardeuc/dewy/www/img/works/96_150x150.jpg' for writing: No such file or directory in /home/stardeuc/dewy/www/lib/image.php on line 69

si vous voulez voici la librairie que j'utilise pour faire le redimensionnement d'image :

<?php
    function resizedname($file,$width,$height){
        $info = pathinfo($file);
        $return = '';

        if($info['dirname'] != '.'){
            $return .= $info['dirname'] . '/';
        }

        $return .= $info['filename'] . "_$width" . "x$height." . $info['extension'];
        return $return;
    }

    function resizeImage($file, $width, $height, $quality = 100){
        # We define the image dir include Theme support
        //$imageDir = (!isset($this->theme)) ? IMAGES : APP.'View'.DS.'Themed'.DS.$this->theme.DS.'webroot'.DS.'img'.DS;
        # We find the right file
        $pathinfo   = pathinfo(trim($file, '/'));
        //$file       = $imageDir . trim($file, '/');
        $output     = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '_' . $width . 'x' . $height . '.' . $pathinfo['extension'];

            # Setting defaults and meta
            $info                         = getimagesize($file);
            list($width_old, $height_old) = $info;
            # Create image ressource
            switch ( $info[2] ) {
                case IMAGETYPE_GIF:   $image = imagecreatefromgif($file);   break;
                case IMAGETYPE_JPEG:  $image = imagecreatefromjpeg($file);  break;
                case IMAGETYPE_PNG:   $image = imagecreatefrompng($file);   break;
                default: return false;
            }
            # We find the right ratio to resize the image before cropping
            $heightRatio = $height_old / $height;
            $widthRatio  = $width_old /  $width;
            $optimalRatio = $widthRatio;
            if ($heightRatio < $widthRatio) {
                $optimalRatio = $heightRatio;
            }
            $height_crop = ($height_old / $optimalRatio);
            $width_crop  = ($width_old  / $optimalRatio);
            # The two image ressources needed (image resized with the good aspect ratio, and the one with the exact good dimensions)
            $image_crop = imagecreatetruecolor( $width_crop, $height_crop );
            $image_resized = imagecreatetruecolor($width, $height);
            # This is the resizing/resampling/transparency-preserving magic
            if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
                $transparency = imagecolortransparent($image);
                if ($transparency >= 0) {
                    $transparent_color  = imagecolorsforindex($image, $trnprt_indx);
                    $transparency       = imagecolorallocate($image_crop, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                    imagefill($image_crop, 0, 0, $transparency);
                    imagecolortransparent($image_crop, $transparency);
                    imagefill($image_resized, 0, 0, $transparency);
                    imagecolortransparent($image_resized, $transparency);
                }elseif ($info[2] == IMAGETYPE_PNG) {
                    imagealphablending($image_crop, false);
                    imagealphablending($image_resized, false);
                    $color = imagecolorallocatealpha($image_crop, 0, 0, 0, 127);
                    imagefill($image_crop, 0, 0, $color);
                    imagesavealpha($image_crop, true);
                    imagefill($image_resized, 0, 0, $color);
                    imagesavealpha($image_resized, true);
                }
            }
            imagecopyresampled($image_crop, $image, 0, 0, 0, 0, $width_crop, $height_crop, $width_old, $height_old);
            imagecopyresampled($image_resized, $image_crop, 0, 0, ($width_crop - $width) / 2, ($height_crop - $height) / 2, $width, $height, $width, $height);
            # Writing image according to type to the output destination and image quality
            switch ( $info[2] ) {
              case IMAGETYPE_GIF:   imagegif($image_resized, $output, 80);    break;
              case IMAGETYPE_JPEG:  imagejpeg($image_resized, $output, 80);   break;
              case IMAGETYPE_PNG:   imagepng($image_resized, $output, 9);    break;
              default: return false;
            }

        return true;  

    }

j'ai déjà posté un commentaire sur les commentaires du tuto du portfolio numéro 5. je n'avais pas vu le forum.
est ce quelqu'un à une idée?
merci d'avance

9 réponses


Bonsoir,

Votre dossier work est-il ouvert en écriture ?

dewy
Auteur

bonjour carouge10,

mon dossier works à les droits d'accès suivant : 705. tu crois ce n'est pas suffisant?

Essayer en 777 pour voir.

dewy
Auteur

je viens de faire le test et j'ai encore le même problème :

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'home/stardeuc/dewy/www/img/works/100_150x150.jpg' for writing: No such file or directory in /home/stardeuc/dewy/www/lib/image.php on line 69

quand je vais dans le fichier img puis works, je ne vois pas ma photo redimensionnée. a mon avis il doit avoir un souci avec cette fonction là non?

Bonjour.
À première vue d'après ton code, j'en déduit que tu es sur CakePHP, notamment sur la V.2 et si c'est bien le cas, je commencerais par te dire, que la constante IMAGES est obsolète :

constant IMAGES
Chemin vers le répertoire images publique.
Obsolète depuis la version 2.4.

Source : Définitions des constantes du noyau
Vu l'erreur, une chose est sure, il n'arrive pas à accéder au dossier et c'est normal, vu que tu lui demandes d'enregistrer dans home/stardeuc/dewy/www/img/works/, alors que ce serait plutôt dans home/stardeuc/dewy/www/webroot/img/works/, tu as oublié le dossier webroot dans le chemin.

Cadeau : Traduction.

dewy
Auteur

bonjour lartak,

en fait je ne suis pas du tout sur cake PHP. ce code je l'ai récupéré en suivant le tuto de grafikart sur la réalisation d'un portfolio en PHP.

ce que je ne comprends pas c'est que le chemin à l'air d'être correct. je veux réellement ranger mes photos redimensionnées dans le fichier works. et ce fichier works on l'atteint grâce au chemin suivant :
home/stardeuc/dewy/www/img/works/

mais est ce que tu crois qu'au lieu d'avoir ce chemin, on aurait un chemin avec le protocole http ça faciliterais les choses non?

et ce fichier works on l'atteint grâce au chemin suivant :
home/stardeuc/dewy/www/img/works/

Pourtant il ne parvient pas à accéder au dossier, c'est ce qu'il dit : Unable to open » Impossible à ouvrir et aussi : No such file or directory » Aucun fichier ou répertoire de ce nom.

mais est ce que tu crois qu'au lieu d'avoir ce chemin, on aurait un chemin avec le protocole http ça faciliterais les choses non?

Surtout pas en lui fournissant l'adresse url de destination, il faut le faire via le chemin et en absolu.

Bonjour,

est-ce que le répertoire /home/stardeuc/dewy/www/img/works/ existe bien ? Si non il faut le créer

dewy
Auteur

Les dossiers existent bien. Ils sont crees et correspondent à cette arborescence.

Merci connected