php - png images automatically named alphabetically -
i have string 100 characters long. want form .png
image each character of string. here code
$grid_ch = "pknhvjayclgcoljwkriwnykoticrnxuxizumpefpshaamhfboimlkvidqksoatlltiicyestieihaasdqpltdwhldxsvcqrhsboj"; $grid_ch_arr = str_split($grid_ch); foreach($grid_ch_arr $k=>$v){ header("content-type: image/png"); $image = imagecreatetruecolor(20, 30); $fill = imagecolorallocate($image, 255,255,255); $text_color = imagecolorallocate($image, 0,0,0); $border = imagecolorallocate($image, 255,255,255); imagefilltoborder($image, 0, 0, $border, $fill); imagestring($image, 5, 2, 2, $v, $text_color); $image_path = "../images/" . $v . ".png"; imagepng($image,$image_path); echo $v . ","; }
my problem images formed a.png till z.png. why images being named english alphabets , not characters string. tried echoing characters @ end of the script , working fine.
please help.
if want files named 1.png, 2.png , on, change line:
$image_path = "../images/" . $v . ".png";
to one:
$image_path = "../images/" . $k . ".png";
or change $k
$k+1
, if want images named 1 100, , not 0 99.
$image_path = "../images/" . $k+1 . ".png";
Comments
Post a Comment