PHP dynamically generates random images of a specified size

Source: Internet
Author: User
The example in this paper describes how PHP dynamically generates random images of a specified size. Share to everyone for your reference, as follows:

<?php$image_width = +, $image _height = +, $image _str = ", if (Isset ($_get[' W '])) {$image _width = intval ($_get[' W ']) ;} if (Isset ($_get[' h '))) {$image _height = intval ($_get[' h ']);} if (Isset ($_get[' s ')) {$image _str = $_get[' s '];} $img = Imagecreate ($image _width, $image _height); $color = Imagecolorallocate ($img, Mt_rand (157,255), Mt_rand (157,255), Mt_rand (157,255)) Imagefilledrectangle ($img, 0, $image _height, $image _width, 0, $color); $step = Mt_rand ($start) = Mt_rand (0, $step); $color = Imagecolorallocate ($img, Mt_rand (200,255), Mt_rand (200,255), Mt_rand (200,255)); Imagesetthickness ($img, Mt_rand (3)), if ($image _height > $image _width) {for ($i = $start; $i < $image _height * 2; $i  + = $step) {imageline ($img, 0, $i, $i, 0, $color);  }}else{for ($i = $start; $i < $image _width * 2; $i + = $step) {imageline ($img, $i, 0, 0, $i, $color);  }}if ($image _str! = ") {$black = imagecolorallocate ($img, 0, 0, 0); Imagestring ($img, 5, 5, $image _str, $black);} Header (' Content-tyPe:image/png '); Imagepng ($img); Imagedestroy ($img); 

More readers interested in PHP related content can view this site topic: "PHP graphics and picture Operation skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP date and Time usage summary", " PHP Primer for object-oriented programming, PHP string Usage Summary, Introduction to PHP+MYSQL database operations, and PHP common database operations Tips Summary

I hope this article is helpful to you in PHP programming.

The above describes the PHP dynamic generation of random images of the size of the method, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.