PHP Operation Imagick Library Print digital Matrix _php Tutorial

Source: Internet
Author: User
Tags vars
PHP Operation Imagick Library can achieve a lot of picture effects, such as on a picture, printing 8*10 digital matrix. The above effects are implemented in the following ways:

PHP Operation Imagick Library code

 
 
  1. //size of lattice
  2. $grid _font_size = 18; //font size
  3. $grid _font_color = "#000" ; //Font color
  4. $grid _width = 36; //width of the lattice
  5. $grid _height = 24; //height of lattice
  6. $grid _origin_x = 15; the starting horizontal of the number in the upper-left corner
  7. $grid _origin_y = 98; the starting ordinate of the number in//upper left corner
  8. #原图
  9. $image = new imagick (' background.jpg ');
  10. #写入密保卡数据
  11. $tmp _grid_origin_x = $grid _origin_x;
  12. $tmp _grid_origin_y = $grid _origin_y;
  13. foreach ( $pData as $k = = $v) {
  14. foreach ( $v as $k _grid_data = $v _ Grid_data) {
  15. $tmp _grid_origin_x += $grid _width ;
  16. $draw = New Imagickdraw ();
  17. $draw ->setfillcolor ($grid _font_color);
  18. $draw ->setfontsize ($grid _font_size);
  19. $draw ->annotation ($tmp _grid_origin_x, $tmp _grid_origin_y, $v _grid_data );
  20. $image ->drawimage ($draw);
  21. }
  22. $tmp _grid_origin_x = $grid _origin_x ;
  23. $tmp _grid_origin_y += $grid _height ;
  24. }
  25. $image->writeimage ($ks _imagesrcpath. $pSN . '. jpg ' );
  26. #释放资源
  27. $image->destroy ();
  28. $draw->destroy ();

The consequence of this is that in each loop, you instantiate a Imagickdraw and execute the DrawImage method, which consumes CPU resources.

Can be optimized from the following two points:

1. Do not need to do new operations every time, one is enough;

2. Do not have to execute the DrawImage method every time, once is enough. In other words, the annotation method seems to have an "attached" meaning, without worrying about the subsequent overwrite of the previous;

PHP Operation Imagick Library is optimized after the code is as follows:

 
 
  1. $draw = New Imagickdraw ();
  2. $draw ->setfillcolor ($grid _font_color);
  3. $draw ->setfontsize ($grid _font_size);
  4. foreach ( $pData as $k = + $v) {
  5. foreach ( $v as $k _grid_data = $v _ Grid_data) {
  6. $tmp _grid_origin_x += $grid _width ;
  7. $draw ->annotation ($tmp _grid_origin_x, $tmp _grid_origin_y, $v _grid _data);
  8. }
  9. $tmp _grid_origin_x = $grid _origin_x ;
  10. $tmp _grid_origin_y += $grid _height ;
  11. }
  12. $image ->drawimage ($draw);


http://www.bkjia.com/PHPjc/446600.html www.bkjia.com true http://www.bkjia.com/PHPjc/446600.html techarticle PHP Operation Imagick Library can achieve a lot of picture effects, such as on a picture, printing 8*10 digital matrix. The above effect is implemented as follows: PHP Operation Imagick Library code//lattice ruler ...

  • Related Article

    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.