<?php
class cropImage {
var $imgSrc , $myImage , $cropHeight , $cropWidth , $x , $y , $thumb ;
function setImage ( $image )
{
//Your Image
$this -> imgSrc = $image ;
//getting the image dimensions
list( $width , $height ) = getimagesize ( $this -> imgSrc );
$endung = substr($image,-4);
$name = substr($image,0,-4);
$endung_ = substr($endung,1);
switch($endung_){
case 'jpg':
$this -> myImage = imagecreatefromjpeg ( $this -> imgSrc ); #or die( "Error: Cannot find image!" );
break;
case 'png':
$this -> myImage = imagecreatefrompng ( $this -> imgSrc ); #or die( "Error: Cannot find image!" );
break;
}
if( $width > $height ) $biggestSide = $width ; //find biggest length
else $biggestSide = $height ;
//The crop size will be half that of the largest side
$cropPercent = .5 ; // This will zoom in to 50% zoom (crop)
$this -> cropWidth = $biggestSide * $cropPercent ;
$this -> cropHeight = $biggestSide * $cropPercent ;
//getting the top left coordinate
$this -> x = ( $width - $this -> cropWidth )/ 2 ;
$this -> y = ( $height - $this -> cropHeight )/ 2 ;
}
function createThumb ()
{
$thumbSize = 60 ; // will create a 250 x 250 thumb
$this -> thumb = imagecreatetruecolor ( $thumbSize , $thumbSize );
imagecopyresampled ( $this -> thumb , $this -> myImage , 0 , 0 , $this -> x , $this -> y , $thumbSize , $thumbSize , $this -> cropWidth , $this -> cropHeight );
}
function renderImage ( $src )
{
$endung = substr($src,-4);
$name = substr($src,0,-4);
$endung_ = substr($endung,1);
switch($endung_){
case 'jpg':
header ( 'Content-type: image/jpeg' );
imagejpeg ( $this -> thumb , 'thumb_'.uniqid().'_'.$name.$endung , 100);
break;
case 'png':
header ( 'Content-type: image/png' );
imagepng ( $this -> thumb , 'thumb_'.uniqid().$name.$endung , 100);
break;
}
imagedestroy ( $this -> thumb );
}
}
$src = $_GET['src'];
$image = new cropImage ;
$image -> setImage ( $src );
$image -> createThumb ();
$image -> renderImage ( $src );
?>