Largeur et hauteur imagecopy

socialGeek Messages postés 9 Date d'inscription   Statut Membre Dernière intervention   -  
Pitet Messages postés 2826 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Voilà j'ai un problème j'aimerais afficher des images sur une image de fond via imagecopy et je bloque pour sélectionner la hauteur et la largeur de l'image de fond !

Voici mon code :

 
    public function render_img_result(){
 
        $listuser = json_decode( urldecode($this->uri->segment(3)) );
 
        $app_id = $this->uri->segment(4);
        $slogans= $this->App_content->get_all_question($app_id);
        $bg = $this->App->get_app($app_id)[0]['img'];
        $dst_im = imagecreatefromjpeg($bg);
 
        $src_im = imagecreatefromjpeg("[http://graph.facebook.com/]".$listuser[0]->id."/picture?type=normal&width=100&height=100");
        $black = imagecolorallocate($dst_im, 0, 0, 0);
 
        // Set Path to Font File
        $font_path = 'assets/fonts/RobotoSlab-Regular.ttf';
 
        // Set Text to Be Printed On Image
        // Slogan 1
 
        imagettftext($dst_im, 14, 0, 200, 70, $black, $font_path, $slogans[0]['content']);
        // Slogan 2
 
        imagettftext($dst_im, 14, 0, 600, 70, $black, $font_path, $slogans[1]['content']);
        // Slogan 3
 
        imagettftext($dst_im, 14, 0, 200, 470, $black, $font_path, $slogans[2]['content']);
        // Slogan 4
 
        imagettftext($dst_im, 14, 0, 600, 470, $black, $font_path, $slogans[3]['content']);
 
 
        //$text = $listuser[0]->name;
        imagettftext($dst_im, 18, 0, 400, 330, $black, $font_path, $listuser[0]->name);
 
        //$text = $listuser[1]->name;
        imagettftext($dst_im, 18, 0, 180, 40, $black, $font_path,$listuser[1]->name);
 
        //$text = $listuser[2]->name;
        imagettftext($dst_im, 18, 0, 580, 40, $black, $font_path, $listuser[2]->name);
 
        //$text = $listuser[3]->name;
        imagettftext($dst_im, 18, 0, 180, 450, $black, $font_path, $listuser[3]->name);
 
        //$text = $listuser[4]->name;
        imagettftext($dst_im, 18, 0, 580, 450, $black, $font_path, $listuser[4]->name);
 
        // // Print Text On Image
 
        // Picure user
 
        imagecopy ( $dst_im , $src_im , 430 , 200 , 0 , 0 , $this->img_size , $this->img_size);
 
        header("Content-type: image/jpeg");
        imagejpeg($dst_im);
        imagedestroy($dst_im);
    }



Pouvez vous m'indiquer comment faire ? S'il vous plait




EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.

1 réponse

Pitet Messages postés 2826 Date d'inscription   Statut Membre Dernière intervention   527
 
Salut,

Pas sûr d'avoir bien compris ta demande mais tu peux utiliser la fonction getimagesize pour récupérer le taille d'une image :
$imageSize = getimagesize($bg);
if (!$imageSize) {
    echo 'Erreur lors de la récupération de la taille de l\'image.';
} else {
    $largeur = $imageSize[0];
    $hauteur = $imageSize[1];
}


https://www.php.net/manual/fr/function.getimagesize.php

Bonne journée,
0