How to resize JPEG or GIF image in PHP

How to resize JPEG or GIF image in PHP How to resize JPEG or GIF image in PHP How to resize JPEG or GIF image in PHP

How to resize JPEG or GIF image in PHP How to resize JPEG or GIF image in PHP How to resize JPEG or GIF image in PHP

How to resize JPEG or GIF image in PHP

for example:

    function createPicture($image,$max_width,$max_height){
        $image = str_replace("//","/",$image);
         
          if (!file_exists($image)) {
                $this->debug_add("Obrázek nenalezen. ".$image,"error");
          }
         
     
         $size     = GetImageSize($image);
         $width     = $size[0];
         $height = $size[1];
         $type     = $size[2];
     
          if ($width>$max_width) {
              $height = $max_width/$width * $height;
              $width  = $max_width;
              $this->debug_add("Prepoctena velikost obrazku na $width x $height ");
          }

          if ($height>$max_height) {
              $width  = $max_height/$height * $width;
              $height = $max_height;
              $this->debug_add("Prepoctena velikost obrazku na $width x $height ");
          }
     
     
        if ($type == 2) {
      
               $src     = imagecreatefromjpeg($image);
               $im         = imagecreatetruecolor($width,$height);
               ImageCopyResized($im,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
               ob_start();                     //Start capturing stdout.
               ImageJPEG($im);                 //As though you were going to send to the browser.
               $imag = ob_get_contents();     //Save bit of stdout we want for later.
               ob_end_clean();    
               return $imag;          
             
         } else {
             $this->debug_add("Obrázek není ve zpracovatelném JPG formátu.(type $type width $width height $height length ".strlen($image).")".$image,"error");
             return null;
         } 
    }
   


Article How to resize JPEG or GIF image in PHP

How to resize JPEG or GIF image in PHP

How to resize JPEG or GIF image in PHP