Filigran png geçerli URL'yi gösteren tutar

0 Cevap php

Ben kullanıcılar tarafından yüklenen görüntüler üzerinde filigran koymak için bir senaryo üzerinde çalışıyorum. Her kullanıcının kendi resmin üzerine kendi kullanıcı adı istiyor, çünkü ben kullanıcı adı ile ilk şeffaf PNG yapmaya karar verdi. Bundan sonra ben birlikte PNG ve yüklenen dosyaları birleştirmek için basit bir filigran tekniği kullanın.

Ben komut dosyası çalışma var, ama bana bir PNG oluşturulduğunda her zaman benim şimdiki adresini gösteren tutar.

Bu kadar kodu:

 <?php
    session_start();

    $username = $_SESSION['login'];
    $filename = "watermarks/$username.png";

    if (file_exists($filename)) {
        exit;
    } elseif ($filename == "undefined") {
        exit;
    }else{


    header("Content-type: image/png"); //Picture Format
    header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Pragma: no-cache"); // NO CACHE

    /*image generation code*/
    //create Image of size 350px x 75px
    $bg = imagecreatetruecolor(500, 100);

    //This will make it transparent
    imagesavealpha($bg, true);

    $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
    imagefill($bg, 0, 0, $trans_colour);

    //Text to be written
    $text = $username;

    // White text
    $white = imagecolorallocate($bg, 255, 255, 255);
    // Grey Text
    $grey = imagecolorallocate($bg, 128, 128, 128);
    // Black Text
    $black = imagecolorallocate($bg, 0,0,0);

    $font = 'fonts/LiberationSans.ttf'; //path to font you want to use
    $fontsize = 20; //size of font


    //Writes text to the image using fonts using FreeType 2
    imagettftext($bg, $fontsize, 0, 125, 50, $black, $font, $text);

    imagettftext($bg, $fontsize, 0, 127, 52, $white, $font, $text);




    //Create image
    header( "Content-type: image/png" );
    //imagepng($bg);

    $save = $filename;
    imagepng($bg, $save, 0, NULL);


    //destroy image
    imagedestroy($bg);

    }
    ?>

Ben bir şey kaçırmış eminim, ama ben anlamaya olamaz.

My second problem is that I can not figure out how to get the text to the center and get rid of the white space around the text. alt text

Ne demek istediğimi görmek için görüntüyü indirebilirsiniz.

Yardımlarınız için şimdiden teşekkür ederiz.

0 Cevap