php利用imagecreatetruecolor動態產生高清圖片代碼

來源:互聯網
上載者:User

//執行個體用我們用imagecreatetruecolor
header ('Content-type: image/png');
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);

//我把這個一起 - 結合較好的例子,然後動態產生的文本。但是,與此成立,我能得到透明背景以及工作。
//執行個體二imagecreatetruecolor
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(175, 15);
imagesavealpha($im, true);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 25, $black);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);

// The text to draw
$text = $_GET['text'];
// Replace path by your own font path
$font = 'catriel regular.ttf';

// Add some shadow to the text
imagettftext($im, 9, 0, 13, 16, $black, $font, $text);

// Add the text
imagettftext($im, 9, 0, 12, 15, $white, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

/*
執行個體三建立透明圖片

如果你想建立一個PNG映像*透明*,其中的背景是完全透明的,所有行動發生在借鑒,除此之外,然後執行下列操作:
*/
$png = imagecreatetruecolor(800, 600);
    imagesavealpha($png, true);

    $trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
    imagefill($png, 0, 0, $trans_colour);
   
    $red = imagecolorallocate($png, 255, 0, 0);
    imagefilledellips教程e($png, 400, 300, 400, 300, $red);
   
    header("Content-type: image/png");
    imagepng($png);
/*
你要做的就是建立一個真正的彩色映像,確保阿爾法儲存狀態是,然後填寫一個顏色,也經曆了阿爾法層級設定為完全透明(127)的映像。

從上面的代碼產生的巴新將有一個完全透明的背景(一紅色圓圈拖到Photoshop中的映像,以瞭解自己)
The resulting PNG from the code above will have a red circle on a fully transparent background (drag the image into Photoshop to see for yourself)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.