Generate image dynamically by url

Asked

Viewed 1,615 times

0

How do I create in PHP with the Placehold.it image server Intervention? Type like this when I write the HTML IMG tag inside src I pass an address that should return an image.

Ex.:

<img src="http://meusite.com/350x150">

1 answer

0


I’m not there these things in php, but I know there is GD (http://php.net/manual/en/ref.image.php) in php

Creating image dynamically through get method (?width=300&height=300):

File: image.php

<?php
header("Content-type:image/png"); // Informa ao nevagador que se trata de uma imagem png
$imagem=imagecreate($_GET["width"],$_GET["height"]); // Cria a imagem com as dimensões definidas
$preto=imagecolorallocate($imagem,0,0,0); // Cria um fundo preto
$branco=imagecolorallocate($imagem,255,255,255); // Armazena uma cor
imagestring($imagem,10,8,8,$_GET["width"]."x".$_GET["height"],$branco); // Escreve na imagem
imagepng($imagem);
imagedestroy($imagem);
?>

Then just call her inside an img tag, for example:

<img src="imagem.php?width=800&height=600">
  • Matheus and in case I already have the image ready on disk as I do to return it? Thanks

  • Thanks a lot for your help. Thanks a lot for your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.