Ignore:
Timestamp:
Dec 6, 2021, 11:33:48 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Image.php

    r92 r95  
    99class Font
    1010{
    11   var $Size;
    12   var $FileName;
    13   var $Color;
     11  public int $Size;
     12  public string $FileName;
     13  public int $Color;
    1414
    1515  function __construct()
     
    2323class Pen
    2424{
    25   var $Color;
    26   var $X;
    27   var $Y;
     25  public int $Color;
     26  public int $X;
     27  public int $Y;
    2828
    2929  function __construct()
     
    3333    $this->Y = 0;
    3434  }
    35 
    3635}
    3736
    3837class Brush
    3938{
    40   var $Color;
     39  public int $Color;
    4140
    4241  function __construct()
     
    4443    $this->Color = COLOR_BLACK;
    4544  }
    46 
    4745}
    4846
    4947class Image
    5048{
    51   var $Image;
    52   var $Type;
    53   var $Font;
    54   var $Pen;
     49  public $Image;
     50  public int $Type;
     51  public Font $Font;
     52  public Pen $Pen;
     53  public Brush $Brush;
    5554
    5655  function __construct()
     
    6362  }
    6463
    65   function SaveToFile($FileName)
     64  function SaveToFile(string $FileName): void
    6665  {
    6766    if ($this->Type == IMAGETYPE_JPEG)
     
    7170    if ($this->Type == IMAGETYPE_GIF)
    7271    {
    73       imagegif ($this->Image, $FileName);
     72      imagegif($this->Image, $FileName);
    7473    } else
    7574    if ($this->Type == IMAGETYPE_PNG)
     
    7978  }
    8079
    81   function LoadFromFile($FileName)
     80  function LoadFromFile(string $FileName): void
    8281  {
    8382    $ImageInfo = getimagesize($FileName);
     
    8988    if ($this->Type == IMAGETYPE_GIF)
    9089    {
    91       $this->Image = imagecreatefromgif($FileName);
     90      $this->Image = imagecreatefromgif ($FileName);
    9291    } else
    9392    if ( $this->Type == IMAGETYPE_PNG)
     
    9796  }
    9897
    99   function Output()
     98  function Output(): void
    10099  {
    101     $this->SaveToFile(NULL);
     100    $this->SaveToFile('');
    102101  }
    103102
    104   function SetSize($Width, $Height)
     103  function SetSize(int $Width, int $Height): void
    105104  {
    106105    $NewImage = imagecreatetruecolor($Width, $Height);
     
    110109  }
    111110
    112   function GetWidth()
     111  function GetWidth(): int
    113112  {
    114113    return imagesx($this->Image);
    115114  }
    116115
    117   function GetHeight()
     116  function GetHeight(): int
    118117  {
    119118    return imagesy($this->Image);
    120119  }
    121120
    122   function TextOut($X, $Y, $Text)
     121  function TextOut(int $X, int $Y, string $Text): void
    123122  {
    124123    imagettftext($this->Image, $this->Font->Size, 0, $X, $Y, $this->ConvertColor($this->Font->Color), $this->Font->FileName, $Text);
    125124  }
    126125
    127   function ConvertColor($Color)
     126  function ConvertColor(int $Color): int
    128127  {
    129128    return imagecolorallocate($this->Image, ($Color >> 16) & 0xff, ($Color >> 8) & 0xff, $Color & 0xff);
    130129  }
    131130
    132   function FillRect($X1, $Y1, $X2, $Y2)
     131  function FillRect(int $X1, int $Y1, int $X2, int $Y2): void
    133132  {
    134133    imagefilledrectangle($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Brush->Color));
    135134  }
    136135
    137   function Line($X1, $Y1, $X2, $Y2)
     136  function Line(int $X1, int $Y1, int $X2, int $Y2): void
    138137  {
    139138    imageline($this->Image, $X1, $Y1, $X2, $Y2, $this->ConvertColor($this->Pen->Color));
Note: See TracChangeset for help on using the changeset viewer.