Skip to content

Instantly share code, notes, and snippets.

@sabbir268
Created December 23, 2020 10:12
Show Gist options
  • Select an option

  • Save sabbir268/f2f0fbf08625194f81f1e5148801c8c5 to your computer and use it in GitHub Desktop.

Select an option

Save sabbir268/f2f0fbf08625194f81f1e5148801c8c5 to your computer and use it in GitHub Desktop.

Revisions

  1. sabbir268 created this gist Dec 23, 2020.
    36 changes: 36 additions & 0 deletions add-text.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?php
    $text = "NAVID";

    $image = imagecreatefrompng('image.png');


    $textColor = imagecolorallocate($image, 255, 255, 254);
    $white = imagecolorallocate($image, 255, 255, 255);
    $col_transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
    imagefill($image, 0, 0, $col_transparent);
    imagecolortransparent($image, $col_transparent);
    //Full Font-File Path
    $fontPath = 'C:/xampp/htdocs/personal/imgae/verdana.ttf';

    foreach (str_split($text) as $key => $value) {
    imagettftext($image, 50, $key*10, 1020+(50*$key), 662+(50*$key), $textColor, $fontPath, $value);
    }
    // imagettftext($image, 50, -4, 1200, 650, $textColor, $fontPath, "HELLO");

    //Set Browser Content Type
    header('Content-type: image/png');
    /** Download image */
    // header('Content-Description: File Transfer');
    // header('Content-Type: application/octet-stream');
    // header('Content-Disposition: attachment; filename=image.png');
    // header('Content-Transfer-Encoding: binary');
    // header('Connection: Keep-Alive');
    // header('Expires: 0');
    // header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    // header('Pragma: public');

    //Send Image To Browser
    imagepng($image);

    //Clear Image From Memory
    imagedestroy($image);