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 :

Redimension d'une image [PHP 5.1]


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Inscrit en
    Octobre 2007
    Messages
    184
    Détails du profil
    Informations personnelles :
    Âge : 46

    Informations forums :
    Inscription : Octobre 2007
    Messages : 184
    Points : 81
    Points
    81
    Par défaut Redimension d'une image
    Bonjour,

    j'utilise dans mon site le script "jQuery uploadify" pour uploader des images, tout fonctionne bien, mais quand j'essaye de télécharger une image de grande dimension (en px) le script sauvegarde l'image à sa taille réelle mais il n'arrive pas a sauvegarder la copie redimensionnée.
    Voici le code :
    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
     
    $(document).ready(function() {
    	$("#uploadify").uploadify({
    		'uploader'   : 'scripts/uploadify.swf',
    		'script'       : 'scripts/uploadify.php',
    		'cancelImg' : 'cancel.png',
    		'folder'       : 'fichier',
    		'queueID'    : 'fileQueue',
    		'fileDesc'	: 'jpg, gif',
    		'fileExt'	: '*.jpg;*.gif',
    		'auto'         : true,
    		'multi'         : false,
    		'buttonText' :'Parcourir...',
    		'scriptData': {'variable': '....'},
    		'method'       : 'GET',
    		'onComplete'  : function(event,queueID,fileObj,response,data)
    		 {
                 $('#thumbnails').append('<img src="' + response + '" />' );
             },
    		 'onAllComplete' : function() {
      			location.reload();
    			}
    		});
    });
    et voici la page uploadify.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
     
    require_once("../codelibrary/inc/variables.php");
    if (!empty($_FILES)) {
    $tp = microtime();
    	$tempFile =$_FILES['Filedata']['tmp_name'];
    	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    	$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    	 $targetFile =  $targetPath .substr($_FILES['Filedata']['name'], 0, -4).$tp.strtolower(substr($targetFile, -4));
     
    	$segment = array();
    	$variable = $_GET['variable'];
    	$tock = strtok($variable, "/");
    	while ($tock != false)
      	{
     	 array_push($segment,$tock); 
      	$tock = strtok("/");
      	}  
    $rqt=mysql_query('INSERT INTO ....');
     
    if(!$rqt){
    $ALERT = "errorr";
    } 
    move_uploaded_file($tempFile,$targetFile);
     
    $imgsize = getimagesize($targetFile);
    switch(strtolower(substr($targetFile, -3)))
    {
        case "jpg":
            $image = imagecreatefromjpeg($targetFile);    
        break;
        case "png":
            $image = imagecreatefrompng($targetFile);
        break;
        case "gif":
            $image = imagecreatefromgif($targetFile);
        break;
        default:
            exit;
        break;
    }
     
    $width = 100; //New width of image    
    $height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
     
    $src_w = $imgsize[0];
    $src_h = $imgsize[1];
     
    $picture = imagecreatetruecolor($width, $height);
    imagealphablending($picture, false);
    imagesavealpha($picture, true);
    $bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h); 
     
    if($bool){
        switch(strtolower(substr($targetFile, -3))){
            case "jpg":
                header("Content-Type: image/jpeg");
                $bool2 = imagejpeg($picture,$targetPath."Thumb/".substr($_FILES['Filedata']['name'], 0, -4).$tp.strtolower(substr($targetFile, -4)) ,80);
     
            break;
            case "png":
                header("Content-Type: image/png");
                imagepng($picture,$targetPath."Thumbs/".substr($_FILES['Filedata']['name'], 0, -4).$tp.strtolower(substr($targetFile, -4)));
            break;
            case "gif":
                header("Content-Type: image/gif");
                imagegif($picture,$targetPath."Thumb/".substr($_FILES['Filedata']['name'], 0, -4).$tp.strtolower(substr($targetFile, -4)));
            break;
        }
    }
    }
    Sachant que dans phpinfo() j'ai memory_limit=32M

    Merci pour votre aide

  2. #2
    Membre régulier
    Inscrit en
    Octobre 2007
    Messages
    184
    Détails du profil
    Informations personnelles :
    Âge : 46

    Informations forums :
    Inscription : Octobre 2007
    Messages : 184
    Points : 81
    Points
    81
    Par défaut
    Personne n'a aucune solution ?

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

Discussions similaires

  1. [GD] Redimension et upload d'une image
    Par gpsevasion dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 18/04/2010, 19h57
  2. redimension d'une image
    Par cicelle dans le forum Tkinter
    Réponses: 22
    Dernier message: 05/06/2009, 20h15
  3. redimension d'une image
    Par ninasec dans le forum MATLAB
    Réponses: 1
    Dernier message: 07/04/2009, 13h36
  4. [ImageMagick] Redimension d'une image
    Par Shin_RockmanX dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 24/04/2006, 21h17

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