TAILIEUCHUNG - Phát triển web với PHP và MySQL - p 44

Generating Images CHAPTER 19 405 3. Outputting the final graphic 4. Cleaning up resources We’ll begin by looking at a very simple image creation script. This script is shown in Listing . LISTING —Outputs a Simple Line Graph with the Label Sales The output from running this script is shown in Figure . We’ll walk through the steps of creating this image one by one. 19 GENERATING IMAGES Creating a Canvas Image To begin building or changing an image in PHP, you will need to create an image identifier. There are two basic ways to. | Generating Images 405 Chapter 19 3. Outputting the final graphic 4. Cleaning up resources We ll begin by looking at a very simple image creation script. This script is shown in Listing . Listing Outputs a Simple Line Graph with the Label Sales set up image height 200 width 200 im ImageCreate width height white ImageColorAllocate im 255 255 255 black ImageColorAllocate im 0 0 0 draw on image ImageFill im 0 0 black ImageLine im 0 0 width height white ImageString im 4 50 150 Sales white output image Header Content-type image png ImagePng im clean up ImageDestroy im The output from running this script is shown in Figure . We ll walk through the steps of creating this image one by one. Creating a Canvas Image To begin building or changing an image in PHP you will need to create an image identifier. There are two basic ways to do this. One is to create a blank canvas which you can do with a call to the ImageCreate function as we have done in this script with the following im ImageCreate width Sheight You need to pass two parameters to ImageCreate . The first is the width of the new image and the second is the height of the new image. The function will return an identifier for the new image. These work a lot like file handles. 19 Generating Images 406 Advanced PHP Techniques Part IV Figure The script draws a black background and then adds a line and a text label for the image. An alternative way is to read in an existing image file that you can then filter resize or add to. You can do this with one of the functions ImageCreateFromPNG ImageCreateFromJPEG or ImageCreateFromGIF depending on the file format you are reading in. Each of these takes the filename as a parameter as in for example im ImageCreateFromPNG An example is shown later in this chapter using existing images to create buttons on-the-fly. Drawing or Printing Text onto the Image There are really two stages to drawing or printing text on the image. First you must

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.