LucianoCharles2017

Classe Carteirinha

May 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2. class Carteirinha {
  3.  
  4.     private $img;
  5.     private $largura;
  6.     private $altura;
  7.     private $transparencia;
  8.     private $imagem_carteira;
  9.     private $foto;
  10.     private $nome_aluno;
  11.     private $red, $green, $blue, $cor_texto;
  12.     private $expessura_fonte, $esquerda, $topo;
  13.     private $f_esquerda, $f_topo, $f_largura, $f_altura;
  14.  
  15.     public function __construct($largura, $altura) {
  16.         $this->largura = $largura;
  17.         $this->altura = $altura;
  18.         $this->img = imagecreatetruecolor($largura, $altura);
  19.         imagesavealpha($this->img, true);
  20.         $this->transparencia = imagecolorallocatealpha($this->img, 0, 0, 0, 100);
  21.         imagefill($this->img, 0, 0, $this->transparencia);
  22.     }
  23.  
  24.     public function setImagemCarteira($imagem) {
  25.         $this->imagem_carteira = imagecreatefromjpeg($imagem);
  26.     }
  27.  
  28.     public function setFoto($imagem) {
  29.         $this->foto = imagecreatefromjpeg($imagem);
  30.     }
  31.  
  32.     public function setNomeAluno($nome_aluno) {
  33.         $this->nome_aluno = $nome_aluno;
  34.     }
  35.  
  36.     public function setCorTexto($red, $green, $blue) {
  37.         $this->red = $red;
  38.         $this->green = $green;
  39.         $this->blue = $blue;
  40.  
  41.         $this->cor_texto = imagecolorallocate($this->img, $red, $green, $blue);
  42.     }
  43.  
  44.     public function setTexto($expessura_fonte, $esquerda, $topo) {
  45.         $this->expessura_fonte = $expessura_fonte;
  46.         $this->esquerda = $esquerda;
  47.         $this->topo = $topo;
  48.     }
  49.  
  50.     public function setTamanhoFoto($esquerda, $topo, $altura, $largura) {
  51.         $this->f_esquerda = $esquerda;
  52.         $this->f_topo = $topo;
  53.         $this->f_altura = $altura;
  54.         $this->f_largura = $largura;
  55.     }
  56.  
  57.     public function gerar($nome_da_carteira) {
  58.         imagecopy($this->img, $this->imagem_carteira, 0, 0, 0, 0, $this->largura, $this->altura);
  59.         imagecopy($this->img, $this->foto, $this->f_esquerda, $this->f_topo, 0, 0, $this->f_largura, $this->f_altura);
  60.  
  61.         imagestring($this->img, $this->expessura_fonte, $this->esquerda, $this->topo, $this->nome_aluno, $this->cor_texto);
  62.  
  63.         header("Content-type: image/jpg");
  64.         imagejpeg($this->img);
  65.         imagejpeg($this->img, "{$nome_da_carteira}.jpg", 100);
  66.         imagedestroy($this->img);
  67.     }
  68.  
  69. }
  70.  
  71. $carteirinha = new Carteirinha(578, 318);
  72. $carteirinha->setImagemCarteira("carteira.jpg");
  73. $carteirinha->setFoto("foto.jpg");
  74. $carteirinha->setTamanhoFoto(22, 22, 138, 121);
  75. $carteirinha->setNomeAluno("Luciano Charles de Souza");
  76. $carteirinha->setTexto(5, 174, 40);
  77. $carteirinha->setCorTexto(0, 0, 0);
  78.  
  79.  
  80. $carteirinha->gerar("carteira_de_Luciano_Charles");
Advertisement
Add Comment
Please, Sign In to add comment