[GD] Texte centrer dans un rectangle

Par Marshall Sad, il y a 9 ans


Bonjour,

Alors voilà pour terminer mon site je dois centrer du texte dans un rectangle, pour cela je voudrais utilisez imagettfbbox mais le problème c'est que la longueur texte est variable ( Noms et prénom de l'utilisateur )

Je ne vois pas trop comment utiliser cette fonction pour qu'elle centre le texte selon sa taille !

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); $black = imagecolorallocate($dst_im, 0, 0, 0); $white = imagecolorallocate($dst_im, 255, 255, 255); // Set Path to Font File $font_path = 'assets/fonts/RobotoSlab-Regular.ttf'; // Noms et Prénom de l'utilisateur $padding = 50 + (213 - strlen( $listuser[0]->name ) * 8 ) / 2; imagettftext($dst_im, 40, 0, $padding, 460, $black, $font_path, $listuser[0]->name); // Noms et prénom d'un amis $padding = 630 + (213 - strlen( $listuser[1]->name ) * 8 ) / 2; imagettftext($dst_im, 40, 0, $padding, 460, $black, $font_path,$listuser[1]->name); // Avatar utilisateur $src_im = imagecreatefromjpeg("http://graph.facebook.com/".$listuser[0]->id."/picture?type=normal&width=350&height=350"); imagecopy ( $dst_im , $src_im , 110 , 35 , 0 , 0 , $this->img_size , $this->img_size); imagedestroy($src_im); // Avatar d'un amis $src_im = imagecreatefromjpeg("http://graph.facebook.com/".$listuser[1]->id."/picture?type=normal&width=350&height=350"); imagecopy ( $dst_im , $src_im , 740 , 35 , 0 , 0 , $this->img_size , $this->img_size); imagedestroy($src_im); header("Content-type: image/jpeg"); imagejpeg($dst_im); imagedestroy($dst_im); }

Pouvais vous me conseillez ?

Merci d'avance !

2 réponses

cid5420, il y a 9 ans

pourquoi pas avec bootstrap ?

Marshall Sad, il y a 9 ans

Bonjour,

La c'est la fonction pour cree l'image de partage facebook ( og:image du resultat ) L'image sur mon site par contre est cree avec bootstrap c'est possible de partager cette image sur facebook ?