bonjour,

je me permet de vous envoyer ce message car je suis en train de migrer mon portfolio chez OVH.

j'ai récupérer sur un tuto un script de redimensionnement d'image. celui-ci fonctionne parfaitement en locale mais dès qu'il est en ligne j'ai l'erreur suivante :

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

je précise que j'obtiens cet erreur également pour le format png. je n'arrive pas à comprendre pourquoi ce bug apparait lorsque le site est en ligne. en locale tout fonctionnait bien pourtant!!

je vous mets ci dessous le script trouvé sur le net :

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
 
<?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;  
 
    }
pour le redimensionnement des avatars des comptes administrateurs, voici le code que j'utilise :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
move_uploaded_file($_FILES['avatar']['tmp_name'], IMAGES . '/avatar/' . $avatar_name);
					resizeImage(IMAGES . '/avatar/' . $avatar_name, 32,32);
IMAGES est une constante calculée en PHP voici le code si vous voulez :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
define('IMAGES',WWW_ROOT . DIRECTORY_SEPARATOR . 'img');
j'ai bien vu qu'il existe un code source PHP pour redimensionner les images sur ce forum, mais je voudrais pourquoi cette librairie ne fonctionne en ligne

merci d'avance pour vos lumières

doogie1