In this random practice script I was doing, I was passing some variables to the script with the URL, which means the $_GET method.
[PHP]<?php
header("Content-type: image/png");
$textinput = $_GET['input'];
if ($_GET['size'] == '')
{
$textsize = 24;
}
else
{
$textsize = $_GET['size'];
}
$height = $textsize + 30;
$canvas = imagecreate(800,$height);
$white = imagecolorallocate($canvas,255,255,255);
$black = imagecolorallocate($canvas,0,0,0);;
$ycoord = $height * (3/4);
Imagettftext($canvas,$textsize,0,0,$ycoord,$black, 'SEGOEUI.TTF',$textinput);
imagepng($canvas);
?>[/PHP]
It's a image generation script that outputs some text as an image. (Obviously)
It works perfectly, all except for this problem:
I want the $_GET['size'] argument to be optional. However, if you don't pass "&size=" to the script, it dies because of the undefined index of $_GET['size'].
Basically, I want to make it optional so that if I don't pass it a size, it should just set the size to a default of 24 and continue on.