Hello,

can somebody explain me, how this class is working and how I can use it?

<?
//Images Wrapper for thumbs and other stuffs, require GDLib
//Riccardo Pasquini, 04/04/2001, v0.1
[EMAIL PROTECTED]

class DynaPic
{
      var $m_sPicName;
      var $m_sFormat;
      var $m_hPic;
      var $m_bHandled;
      var $m_sLastError;
      var $m_nThumbX;
      var $m_nThumbY;
      var $m_aHeaders;

      function DynaPic($pic,$format)
      {
             //check if valid format
             if(strtoupper($format)!="PNG" && strtoupper($format)!="GIF" && 
strtoupper($format)!="JPEG")
             {
                  $this->m_sLastError="Invalid format: 
".stripslashes(htmlentities($format));
                  return false;
             }

             //initialize
             $this->m_sFormat=strtoupper($format);
             $this->m_sPicName=$pic;
             $this->m_sLastError="";

             //thumb default resize 50%
             $this->setThumbDimension(0.5);
             $this->m_aHeaders=array("GIF"=>"Content-type: 
image/gif","PNG"=>"Content-type: image/png","JPEG"=>"Content-type: image/jpeg");
             return $this->create();
      }

      function destroy()
      {
             if($this->m_bHandled)
             {
                 imagedestroy($this->m_hPic);
                 $this->m_bHandled=false;
             }
      }

      function create()
      {
             $this->destroy();

             
eval("\$this->m_hPic=@imagecreatefrom".$this->m_sFormat."('".$this->m_sPicName."');");

             //check if init succeded
             if(!$this->m_hPic)
             {
                  $m_sLastError="Unable to open 
".stripslashes(htmlentities($this->m_sPicName))." as 
".stripslashes(htmlentities($this->m_sFormat));
                  $this->m_bHandled=false;
                  return false;
             }
             else
             {
                  $this->m_bHandled=true;
                  return true;
             }
      }

      //property access
      function getLastError()
      {
             return $this->m_sLastError;
      }

      function setPicName($pic)
      {
             $this->m_sPicName=$pic;
             $this->m_bHandled=false;
      }

      function getPicName()
      {
             return $this->m_sPicName;
      }

      function setThumbDimension($pctg)
      {
             $size = GetImageSize($this->m_sPicName);

             $this->m_nThumbX=$size[0]*$pctg;
             $this->m_nThumbY=$size[1]*$pctg;
      }

      function getThumbDimension(&$w,&$h)
      {
             $w=$this->m_nThumbX;
             $h=$this->m_nThumbY;
      }

      function setPicFormat($format)
      {
             if(strtoupper($format)!="PNG" && strtoupper($format)!="GIF" && 
strtoupper($format)!="JPEG")
             {
                  $this->m_sLastError="Invalid format: 
".stripslashes(htmlentities($format));
                  return false;
             }
             else
             {
                  $this->m_sFormat=strtoupper($format);
                  $this->m_bHandled=false;
             }

             return true;
      }

      function getPicFormat()
      {
             return $this->m_sFormat;
      }

      //display functions
      function thumb()
      {
            if($this->m_bHandled)
            {
                $size = GetImageSize($this->m_sPicName);
                $picTmp=imagecreate($this->m_nThumbX,$this->m_nThumbY);
                imagecopyresized($picTmp, $this->m_hPic, 0, 0, 0, 0, $this->m_nThumbX, 
$this->m_nThumbY, $size[0], $size[1]);
                header($this->m_aHeaders[$this->m_sFormat]);
                switch($this->m_sFormat)
                {
                         case 'JPEG':
                               imagejpeg($picTmp);
                               break;
                         case 'GIF':
                               imagegif($picTmp);
                               break;
                         case 'PNG':
                               imagepng($picTmp);
                               break;
                }
                imagedestroy($picTmp);
            }
      }

      function full()
      {
            if($this->m_bHandled)
            {
                header($this->m_aHeaders[$this->m_sFormat]);
                switch($this->m_sFormat)
                {
                         case 'JPEG':
                               imagejpeg($this->m_hPic);
                               break;
                         case 'GIF':
                               imagegif($this->m_hPic);
                               break;
                         case 'PNG':
                               imagepng($this->m_hPic);
                               break;
                }
            }
      }

      function view($width, $height)
      {
            if($this->m_bHandled)
            {
                $size = GetImageSize($this->m_sPicName);
                $picTmp=imagecreate($width,$height);
                imagecopyresized($picTmp, $this->m_hPic, 0, 0, 0, 0, $width, $height, 
$size[0], $size[1]);
                header($this->m_aHeaders[$this->m_sFormat]);
                switch($this->m_sFormat)
                {
                         case 'JPEG':
                               imagejpeg($picTmp);
                               break;
                         case 'GIF':
                               imagegif($picTmp);
                               break;
                         case 'PNG':
                               imagepng($picTmp);
                               break;
                }
                imagedestroy($picTmp);
            }
      }
}


?>

I don't know how I can interact with this class.

Please tell me how

Good Bye

Sascha Braun

Reply via email to