Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

[Noob] Image uploading doesn't works everytime

$
0
0
Hey :)
 
I found a script that works for the upload and resize of images.
 
What's weird is that the upload/resize works for some JPG's (the screen impression) but not for some others (photoshop ones or the photos i took with my phone)
 
Fatal error: Function name must be a string in /home/a7805396/public_html/fxphoto.php on line 20
 
For another JPG, no error, the BDD uploads but the image doesn't resize/upload...
 
Here's my include fxphoto.php
 
<?php
    function creerImageDepuis($source) {
        $imageCreateFrom = array(
            "jpg" => "imagecreatefromjpeg",
            "png" => "imagecreatefrompng"
        );
 
        // Récupération de l'extention du fichier
        $extention = pathinfo($source, PATHINFO_EXTENSION);
        $extention = strtolower($extention);
        $extention = ($extention == "jpeg") ? "jpg" : $extention;
 
        $function = $imageCreateFrom[$extention];
        $image_source = $function($source);
 
        // Sauvegarde de la transparence de l'image
        imagealphablending($image_source, false);
        imagesavealpha($image_source, true);
 
        return $image_source;
    }
    
    function creerImage($image, $destination, $quality = 100) {
        $imageCreate = array(
            "jpg" => "imagejpeg",
            "png" => "imagepng"
        );
 
        // Récupération de l'extention du fichier
        $extention = pathinfo($destination, PATHINFO_EXTENSION);
        $extention = strtolower($extention);
 
        $function = $imageCreate[$extention];
 
        if ($extention == "jpg") {
            $function($image, $destination, $quality);
        } else {
            $function($image, $destination);
        }
 
        imagedestroy($image);
    }
    
    function redimensionneImage($source, $destination, $width, $height,
        $quality = 100){
        $image_source = creerImageDepuis($source);
 
        $size = getimagesize($source);
 
        if ($width == -1 || $height == -1) { // Si valeur automatique
            // On remplace le -1 par la valeur calculée
            $height = ($width != -1 && $height == -1) ?
                (($size[1] * $width) / $size[0]) : $height;
            $width = ($width == -1 && $height != -1) ?
                (($size[0] * $height) / $size[1]) : $width;
        } else if ($size[0] < $size[1]) { // Si portrait
            $tmp = $height;
            $height = $width;
            $width = $tmp;
        }
 
        $image_redim = @imagecreatetruecolor($width, $height);
        imagealphablending($image_redim, false);
        imagesavealpha($image_redim, true);
 
        imagecopyresampled ($image_redim, $image_source, 0, 0, 0, 0,
            $width, $height, $size[0], $size[1]);
 
        imagedestroy($image_source);
 
        creerImage($image_redim, $destination);
    }
?>

 

 

How can I fix that ?
 
Thanks
 
iSteelZ
 
PS : Sorry for the english and the variables names, I'm French

Viewing all articles
Browse latest Browse all 13200

Trending Articles