You are here

function resizeimage in Brilliant Gallery 5.4

Same name and namespace in other branches
  1. 5.3 image.php \resizeimage()
  2. 6.4 functions.inc \resizeimage()
  3. 6 image.php \resizeimage()
  4. 6.2 image.php \resizeimage()
  5. 6.3 image.php \resizeimage()
  6. 7.2 OLD_brilliant_gallery_functions.inc \resizeimage()
  7. 7 brilliant_gallery_functions.inc \resizeimage()
2 calls to resizeimage()
resizeimage_wrapper_dbcache in ./image.php
resizeimage_wrapper_filecache in ./image.php

File

./image.php, line 113

Code

function resizeimage($imgp, $imgw, $imgh) {
  $imagepath = base64_decode($imgp);

  #echo '.... ' . base64_decode( $imgp );

  #flush();die(' stop!');

  # Thanks to Michał Albrecht!
  $suffix = strtolower(substr($imagepath, -4));
  $imgsize = @getimagesize($imagepath);

  # http://be.php.net/getimagesize
  $head = "Content-type: {$imgsize['mime']}";
  if ($suffix == ".gif") {

    #$head = "Content-type: image/gif";
    $img = imagecreatefromgif($imagepath);
    if (!$img) {
      brokenimage("Error loading GIF");
    }
  }
  else {
    if ($suffix == ".jpg" or $suffix == "jpeg") {

      # Thanks to Michał Albrecht!

      #$head = "Content-type: image/jpeg";
      $img = imagecreatefromjpeg($imagepath);
      if (!$img) {
        brokenimage("Error loading JPG");
      }
    }
    else {
      if ($suffix == ".png") {

        #$head = "Content-type: image/png";
        $img = imagecreatefrompng($imagepath);
        if (!$img) {
          brokenimage("Error loading PNG");
        }
      }
    }
  }

  # Resize the image
  $src_h = ImageSY($img);
  $src_w = ImageSX($img);
  $dst_img = imagecreatetruecolor($imgw, $imgh);
  imagecopyresampled($dst_img, $img, 0, 0, 0, 0, $imgw, $imgh, $src_w, $src_h);
  $img = $dst_img;
  imageinterlace($img, 1);
  imagecolortransparent($img);
  ob_start();
  if ($suffix == ".gif") {
    Imagegif($img);
  }
  else {
    if ($suffix == ".jpg" or $suffix == ".jpeg") {
      Imagejpeg($img, '', 80);
    }
    else {
      if ($suffix == ".png") {
        Imagepng($img);
      }
    }
  }
  $result = ob_get_clean();

  #ImageDestroy($img);
  $result = serialize(array(
    $head,
    base64_encode($result),
  ));
  return $result;
}