?? 18c01-2.php
字號:
<?php// We are going to insert a copyright statement onto a graphic.// Read the graphic into memory, this is a JPEG so we use that function:$gfx = imagecreatefromjpeg('eli.jpg');// Now, we want to place this statement at the bottom// so we need to determine the dimensions of our image:$width = imagesx($gfx);$height = imagesy($gfx);// Define our string we are going to print:$statement = 'Copyright 2006 - eliw.com';$font = 'arial';// We are going to use truetype fonts, and would like a fontsize of 11// If that ends up being to wide for our image, we need to go smaller.foreach (range(11, 1) as $fontsize) { // Calculate the bounding box of this text $box = imagettfbbox($fontsize, 0, $font, $statement); // Use the lower left X (0) and the upper right X (4) to calculate width $fontw = abs($box[4] - $box[0]); // Is this, plus 4 to give spacing, less than our image? if ($fontw + 4 <= $width) { // Yay, it is. Break out of this loop and continue with this size. break; }}// height: use lower left Y(1) and upper right Y(5) to calculate$fonth = abs($box[5] - $box[1]);// We also need to know how far below the baseline the font drops:// Snag this from the lower left corner Y value.$basel = $box[1];// We want two colors for this. We need to display a black background// and want white text on top of that. Declare those colors via RGB:$black = imagecolorallocate($gfx, 0, 0, 0);$white = imagecolorallocate($gfx, 255, 255, 255);// Draw a rectangle in bottom left corner to be a background of the text:imagefilledrectangle($gfx, $width - $fontw - 4, $height - $fonth - 4, $width, $height, $black);// Now, print this statement out in the bottom right corner.imagettftext($gfx, // The graphics object to draw on $fontsize, // The font size to use. 0, // The slant angle of the text $width - $fontw - 2, // X value of left side of text $height - $basel - 2, // Y value of the text baseline $white, // The color to do it with. $font, // The font to use. $statement); // The text to print // We are now done with our manipulations.// Let the browser know that we are going to output this as a PNGheader('Content-type: image/png');// And then output our new image:imagepng($gfx);?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -