Need Help Understanding this PHP Code

前端 未结 5 1571
感情败类
感情败类 2021-01-23 07:48

i am aware of the basics like what is a function, a class, a method etc. however i am totally confused on what exactly the below code does to read the image, i read it somewhere

5条回答
  •  忘了有多久
    2021-01-23 08:47

    class Image
    {
      public $source = '';
    
        function __construct($filename)
        {
          $fp = fopen($filename, 'rb') or die("Image $filename doesn't exist");
          $buf = '';
          while(!feof($fp))
          {
            $buf .= fgets($fp, 4096);
          }
          $this->source = imagecreatefromstring($buf);
        }
    }
    $image = new Image('image.jpg');
    /* use $image->source for image processing */
    header('Content-Type: image/jpeg');
    imagejpeg($image->source);
    

提交回复
热议问题