You are here

function cropimage in TinyBrowser 7

1 call to cropimage()
tinybrowser.php in tinybrowser/tinybrowser.php

File

tinybrowser/fns_tinybrowser.php, line 167

Code

function cropimage($im, $x1, $y1, $new_w, $new_h, $urlandname, $comp, $imagetype) {
  $width = imagesx($im);
  $height = imagesy($im);
  if ($width >= $new_w && $height >= $new_h) {
    if (function_exists('imagecopyresampled') && $imagetype != 'image/gif') {
      $newim = imagecreatetruecolor($new_w, $new_h);
    }
    else {
      $newim = imagecreate($new_w, $new_h);
    }

    // additional processing for png / gif transparencies (credit to Dirk Bohl)
    if ($imagetype == 'image/x-png' || $imagetype == 'image/png') {
      imagealphablending($newim, false);
      imagesavealpha($newim, true);
    }
    elseif ($imagetype == 'image/gif') {
      $originaltransparentcolor = imagecolortransparent($im);
      if ($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal($im)) {
        $transparentcolor = imagecolorsforindex($im, $originaltransparentcolor);
        $newtransparentcolor = imagecolorallocate($newim, $transparentcolor['red'], $transparentcolor['green'], $transparentcolor['blue']);
        imagefill($newim, 0, 0, $newtransparentcolor);
        imagecolortransparent($newim, $newtransparentcolor);
      }
    }
    imagecopyresampled($newim, $im, 0, 0, $x1, $y1, $new_w, $new_h, $new_w, $new_h);
    if ($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg') {
      imagejpeg($newim, $urlandname, $comp);
    }
    else {
      if ($imagetype == 'image/x-png' || $imagetype == 'image/png') {
        imagepng($newim, $urlandname, substr($comp, 0, 1));
      }
      elseif ($imagetype == 'image/gif') {
        imagegif($newim, $urlandname);
      }
    }
    imagedestroy($newim);
  }
}