imagejpeg无法在for循环

时间:2015-12-06 18:49:23

标签: php arrays image

我在变量中有一个数组:

$fected_data 

当我打印数组时,我明白了:

Array
(
[0] => Array
    (
        [id] => 1
        [zip] => 47006
        [route] => C001
        [no_mail] => 449
        [type] => Residential 
        [date_time] => abc
    )

[1] => Array
    (
        [id] => 2
        [zip] => 47006
        [route] => C002
        [no_mail] => 677
        [type] => Residential 
        [date_time] => 
    )

[2] => Array
    (
        [id] => 3
        [zip] => 47006
        [route] => H061
        [no_mail] => 9
        [type] => Residential 
        [date_time] => 
    )

[3] => Array
    (
        [id] => 4
        [zip] => 47006
        [route] => R001
        [no_mail] => 449
        [type] => Residential 
        [date_time] => 
    )

[4] => Array
    (
        [id] => 5
        [zip] => 47006
        [route] => R002
        [no_mail] => 566
        [type] => Residential 
        [date_time] => 
    )

[5] => Array
    (
        [id] => 6
        [zip] => 47006
        [route] => R003
        [no_mail] => 513
        [type] => Residential 
        [date_time] => 
    )

[6] => Array
    (
        [id] => 7
        [zip] => 47006
        [route] => R004
        [no_mail] => 536
        [type] => Residential 
        [date_time] => 
    )

[7] => Array
    (
        [id] => 8
        [zip] => 47006
        [route] => R006
        [no_mail] => 479
        [type] => Residential 
        [date_time] => 
    )

[8] => Array
    (
        [id] => 9
        [zip] => 47006
        [route] => R007
        [no_mail] => 637
        [type] => Residential 
        [date_time] => 
    )

[9] => Array
    (
        [id] => 10
        [zip] => 47037
        [route] => R002
        [no_mail] => 510
        [type] => Residential 
        [date_time] => 
    )

[10] => Array
    (
        [id] => 11
        [zip] => 47006
        [route] => R005
        [no_mail] => 474
        [type] => Residential 
        [date_time] => 
    )

[11] => Array
    (
        [id] => 12
        [zip] => 62812
        [route] => C001
        [no_mail] => 504
        [type] => Residential 
        [date_time] => 
    )

[12] => Array
    (
        [id] => 13
        [zip] => 62812
        [route] => C002
        [no_mail] => 470
        [type] => Residential 
        [date_time] => 
    )

[13] => Array
    (
        [id] => 14
        [zip] => 62812
        [route] => C003
        [no_mail] => 366
        [type] => Residential 
        [date_time] => 
    )

[14] => Array
    (
        [id] => 15
        [zip] => 62812
        [route] => C005
        [no_mail] => 429
        [type] => Residential 
        [date_time] => 
    )

现在基于这个数组,我需要写一些快递单,循环通过数组值,我需要把代码负责在嵌套的for循环中写入文本,在foreach中,所以对于第一个图像它工作正常,但是不能看到其他人,逻辑似乎在我的结尾对我正在做的事情很好,但是我想到的是imagejpeg不在循环中工作。请帮助我

foreach($fected_data as $fected)
 {
   $no_of_mailp = $fected['no_mail'];
   $devided_number =  bcdiv($fected['no_mail'], 100, 2).'<br>';

   $totalboxes = explode('.' , $devided_number);
   $totalbundles = $totalboxes['0']+1;

   $zipcode = $fected['zip'];
   $route = $fected['route'];
   $type = $fected['type'];


   for($i=0;$i < $totalbundles;$i++)
   {
    echo $extended_var = $i+1;

    if($extended_var != $totalbundles)
    {
        header('Content-type: image/jpeg');

        $jpg_image = imagecreatefromjpeg('faceslip.jpg');

        $white = imagecolorallocate($jpg_image, 0, 0, 0);

        $font_path = 'arial.ttf';
       $total_mail_pc = 100;

       // zipcode
         $x=150;
        for($i=0;$i<=strlen($zipcode);$i++){
                $print_text=substr($zipcode,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $print_text);
       }
       // Route
          $x=350;
          for($i=0;$i<=strlen($route);$i++){
                $route_text=substr($route,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $route_text);
     }
       // Type
          $x=650;
          for($i=0;$i<=strlen($type);$i++){
                $type_text=substr($type,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $type_text);
         }
          // No of mp
           $x=350;
           for($i=0;$i<=strlen($total_mail_pc);$i++){
                $total_mail_pc_text=substr($total_mail_pc,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 870, $white, $font_path, $total_mail_pc_text);
     }
        // page of page
          $x=600;
          for($i=0;$i<=strlen($extended_var);$i++){
                $extended_var_text=substr($extended_var,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 1000, $white, $font_path, $extended_var_text);
     }
       // page of page
        $x=700;
        for($i=0;$i<=strlen($totalbundles);$i++){
                $totalbundles_text=substr($totalbundles,$i,1);
                $x+=35;
                imagettftext($jpg_image, 50, 0, $x, 1000, $white, $font_path, $totalbundles_text);
     }

        // Send Image to Browser
        $nameoffile = $zipcode.'-'.$route.'-'.$extended_var.'.jpg';
        imagejpeg($jpg_image, $nameoffile);

       // Clear Memory
       imagedestroy($jpg_image);


       }
       else {


         $total_mail_pc = $totalboxes[1];





        }



      }
     }

0 个答案:

没有答案