<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>PHP Resim Crop yazısına yapılan yorumlar</title>
	<atom:link href="http://www.phpdili.com/php/php-resim-crop.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdili.com/php/php-resim-crop.html</link>
	<description>Özgün PHP Dersleri</description>
	<lastBuildDate>Wed, 07 Dec 2011 07:26:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>Yazar: Golgesiz Bilisim</title>
		<link>http://www.phpdili.com/php/php-resim-crop.html/comment-page-1#comment-1142</link>
		<dc:creator>Golgesiz Bilisim</dc:creator>
		<pubDate>Fri, 19 Aug 2011 21:57:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpdili.com/?p=172#comment-1142</guid>
		<description>Bunu da Kullanabilirsiniz.. 
&lt;?php

// TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks
// http://code.google.com/p/timthumb/

// MIT License: http://www.opensource.org/licenses/mit-license.php

/* Parameters allowed: */

// w: width
// h: height
// zc: zoom crop (0 or 1)
// q: quality (default is 75 and max is 100)

// HTML example: 

if( !isset( $_REQUEST[ &quot;src&quot; ] ) ) { die( &quot;no image specified&quot; ); }

// clean params before use
$src = clean_source( $_REQUEST[ &quot;src&quot; ] );

// set document root
$doc_root = get_document_root($src);
                        
// get path to image on file system
$src = $doc_root . &#039;/&#039; . $src;

$new_width = preg_replace( &quot;/[^0-9]+/&quot;, &quot;&quot;, get_request( &#039;w&#039;, 100 ) );
$new_height = preg_replace( &quot;/[^0-9]+/&quot;, &quot;&quot;, get_request( &#039;h&#039;, 100 ) );
$zoom_crop = preg_replace( &quot;/[^0-9]+/&quot;, &quot;&quot;, get_request( &#039;zc&#039;, 1 ) );
$quality = preg_replace( &quot;/[^0-9]+/&quot;, &quot;&quot;, get_request( &#039;9&#039;, 80 ) );

// set path to cache directory (default is ./cache)
// this can be changed to a different location
$cache_dir = &#039;./cache&#039;;

// get mime type of src
$mime_type = mime_type( $src );

// check to see if this image is in the cache already
check_cache( $cache_dir, $mime_type );

// make sure that the src is gif/jpg/png
if( !valid_src_mime_type( $mime_type ) ) {
	$error = &quot;Invalid src mime type: $mime_type&quot;;
	die( $error );
}

// check to see if GD function exist
if(!function_exists(&#039;imagecreatetruecolor&#039;)) {
	$error = &quot;GD Library Error: imagecreatetruecolor does not exist&quot;;
	die( $error );
}

if(strlen($src) &amp;&amp; file_exists( $src ) ) {

	// open the existing image
	$image = open_image( $mime_type, $src );
	if( $image === false ) { die( &#039;Unable to open image : &#039; . $src ); }		

	// Get original width and height
	$width = imagesx( $image );
	$height = imagesy( $image );

	// don&#039;t allow new width or height to be greater than the original
	if( $new_width &gt; $width ) { $new_width = $width; }
	if( $new_height &gt; $height ) { $new_height = $height; }

	// generate new w/h if not provided
	if( $new_width &amp;&amp; !$new_height ) {
		$new_height = $height * ( $new_width / $width );
	}
	elseif($new_height &amp;&amp; !$new_width) {
		$new_width = $width * ( $new_height / $height );
	}
	elseif(!$new_width &amp;&amp; !$new_height) {
		$new_width = $width;
		$new_height = $height;
	}

	// create a new true color image
	$canvas = imagecreatetruecolor( $new_width, $new_height );

	if( $zoom_crop ) {

		$src_x = $src_y = 0;
		$src_w = $width;
		$src_h = $height;

		$cmp_x = $width  / $new_width;
		$cmp_y = $height / $new_height;

		// calculate x or y coordinate and width or height of source

		if ( $cmp_x &gt; $cmp_y ) {

			$src_w = round( ( $width / $cmp_x * $cmp_y ) );
			$src_x = round( ( $width - ( $width / $cmp_x * $cmp_y ) ) / 2 );

		}
		elseif ( $cmp_y &gt; $cmp_x ) {

			$src_h = round( ( $height / $cmp_y * $cmp_x ) );
			$src_y = round( ( $height - ( $height / $cmp_y * $cmp_x ) ) / 2 );

		}
        
		imagecopyresampled( $canvas, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h );

	}
	else {

		// copy and resize part of an image with resampling
		imagecopyresampled( $canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

	}

	// output image to browser based on mime type
	show_image( $mime_type, $canvas, $quality, $cache_dir );
	
	// remove image from memory
	imagedestroy( $canvas );
	
} else {

	if( strlen( $src ) ) { echo $src . &#039; not found.&#039;; } else { echo &#039;no source specified.&#039;; }
	
}

function show_image ( $mime_type, $image_resized, $quality, $cache_dir ) {

	// check to see if we can write to the cache directory
	$is_writable = 0;
	$cache_file_name = $cache_dir . &#039;/&#039; . get_cache_file();        	

	if( touch( $cache_file_name ) ) {
		// give 666 permissions so that the developer 
		// can overwrite web server user
		chmod( $cache_file_name, 0666 );
		$is_writable = 1;
	}
	else {
		$cache_file_name = NULL;
		header( &#039;Content-type: &#039; . $mime_type );
	}
	
	if( stristr( $mime_type, &#039;gif&#039; ) ) {
		imagegif( $image_resized, $cache_file_name );
	}
	elseif( stristr( $mime_type, &#039;jpeg&#039; ) ) {
		imagejpeg( $image_resized, $cache_file_name, $quality );
	}
	elseif( stristr( $mime_type, &#039;png&#039; ) ) {
		imagepng( $image_resized, $cache_file_name, ceil( $quality / 10 ) );
	}
	if( $is_writable ) { show_cache_file( $cache_dir, $mime_type ); }
	exit;

}

function get_request( $property, $default = 0 ) {
	
	if( isset($_REQUEST[$property]) ) {
		return $_REQUEST[$property];
	} else {
		return $default;
	}
	
}

function open_image ( $mime_type, $src ) {

	if( stristr( $mime_type, &#039;gif&#039; ) ) {
		$image = imagecreatefromgif( $src );
	}
	elseif( stristr( $mime_type, &#039;jpeg&#039; ) ) {
		@ini_set(&#039;gd.jpeg_ignore_warning&#039;, 1);
		$image = imagecreatefromjpeg( $src );
	}
	elseif( stristr( $mime_type, &#039;png&#039; ) ) {
		$image = imagecreatefrompng( $src );
	}
	return $image;

}

function mime_type ( $file ) {

    $os = strtolower(php_uname());
	$mime_type = &#039;&#039;;

	// use PECL fileinfo to determine mime type
	if( function_exists( &#039;finfo_open&#039; ) ) {
		$finfo = finfo_open( FILEINFO_MIME );
		$mime_type = finfo_file( $finfo, $file );
		finfo_close( $finfo );
	}

	// try to determine mime type by using unix file command
	// this should not be executed on windows
    if( !valid_src_mime_type( $mime_type ) &amp;&amp; !(eregi(&#039;windows&#039;, php_uname()))) {
		if( preg_match( &quot;/freebsd&#124;linux/&quot;, $os ) ) {
                	$mime_type = trim ( @shell_exec( &#039;file -bi $file&#039; ) );
		}
	}

	// use file&#039;s extension to determine mime type
	if( !valid_src_mime_type( $mime_type ) ) {
		$frags = split( &quot;\.&quot;, $file );
		$ext = strtolower( $frags[ count( $frags ) - 1 ] );
		$types = array(
 			&#039;jpg&#039;  =&gt; &#039;image/jpeg&#039;,
 			&#039;jpeg&#039; =&gt; &#039;image/jpeg&#039;,
 			&#039;png&#039;  =&gt; &#039;image/png&#039;,
 			&#039;gif&#039;  =&gt; &#039;image/gif&#039;
 		);
		if( strlen( $ext ) &amp;&amp; strlen( $types[$ext] ) ) {
			$mime_type = $types[ $ext ];
		}

		// if no extension provided, default to jpg
		if( !strlen( $ext ) &amp;&amp; !valid_src_mime_type( $mime_type ) ) {
			$mime_type = &#039;image/jpeg&#039;;
		}
	}
	return $mime_type;

}

function valid_src_mime_type ( $mime_type ) {

	if( preg_match( &quot;/jpg&#124;jpeg&#124;gif&#124;png/i&quot;, $mime_type ) ) { return 1; }
	return 0;

}

function check_cache ( $cache_dir, $mime_type ) {

	// make sure cache dir exists
	if( !file_exists( $cache_dir ) ) {
		// give 777 permissions so that developer can overwrite
		// files created by web server user
		mkdir( $cache_dir );
		chmod( $cache_dir, 0777 );
	}

	show_cache_file( $cache_dir, $mime_type );

}

function show_cache_file ( $cache_dir, $mime_type ) {

	$cache_file = $cache_dir . &#039;/&#039; . get_cache_file();

	if( file_exists( $cache_file ) ) {
    	
	    if( isset( $_SERVER[ &quot;HTTP_IF_MODIFIED_SINCE&quot; ] ) ) {
		
			// check for updates
			$if_modified_since = preg_replace( &#039;/;.*$/&#039;, &#039;&#039;, $_SERVER[ &quot;HTTP_IF_MODIFIED_SINCE&quot; ] );					
			$gmdate_mod = gmdate( &#039;D, d M Y H:i:s&#039;, filemtime( $cache_file ) );
			
			if( strstr( $gmdate_mod, &#039;GMT&#039; ) ) {
				$gmdate_mod .= &quot; GMT&quot;;
			}
			
			if ( $if_modified_since == $gmdate_mod ) {
				header( &quot;HTTP/1.1 304 Not Modified&quot; );
				exit;
			}

		}
		
		$fileSize = filesize( $cache_file );
		
		// send headers then display image
		header( &quot;Content-Type: &quot; . $mime_type );
		header( &quot;Accept-Ranges: bytes&quot; );
		header( &quot;Last-Modified: &quot; . gmdate( &#039;D, d M Y H:i:s&#039;, filemtime( $cache_file ) ) . &quot; GMT&quot; );
		header( &quot;Content-Length: &quot; . $fileSize );
		header( &quot;Cache-Control: max-age=9999, must-revalidate&quot; );
		header( &quot;Etag: &quot; . md5($fileSize . $gmdate_mod) );						   		
		header( &quot;Expires: &quot; . gmdate( &quot;D, d M Y H:i:s&quot;, time() + 9999 ) . &quot;GMT&quot; );
		readfile( $cache_file );
		exit;

	}
	
}

function get_cache_file () {

	global $quality;

	static $cache_file;
	if(!$cache_file) {
		$frags = split( &quot;\.&quot;, $_REQUEST[&#039;src&#039;] );
		$ext = strtolower( $frags[ count( $frags ) - 1 ] );
		if(!valid_extension($ext)) { $ext = &#039;jpg&#039;; }
		$cachename = get_request( &#039;src&#039;, &#039;timthumb&#039; ) . get_request( &#039;w&#039;, 100 ) . get_request( &#039;h&#039;, 100 ) . get_request( &#039;zc&#039;, 1 ) . get_request( &#039;9&#039;, 80 );
		$cache_file = md5( $cachename ) . &#039;.&#039; . $ext;
	}
	return $cache_file;

}

function valid_extension ($ext) {

	if( preg_match( &quot;/jpg&#124;jpeg&#124;png&#124;gif/i&quot;, $ext ) ) return 1;
	return 0;

}

function clean_source ( $src ) {

	// remove http/ https/ ftp
	$src = preg_replace(&quot;/^((ht&#124;f)tp(s&#124;):\/\/)/i&quot;, &quot;&quot;, $src);
	// remove domain name from the source url
	$src = str_replace($_SERVER[&quot;HTTP_HOST&quot;], &quot;&quot;, $src);

	//$src = preg_replace( &quot;/(?:^\/+&#124;\.{2,}\/+?)/&quot;, &quot;&quot;, $src );
	//$src = preg_replace( &#039;/^\w+:\/\/[^\/]+/&#039;, &#039;&#039;, $src );

	// don&#039;t allow users the ability to use &#039;../&#039; 
	// in order to gain access to files below document root

	// src should be specified relative to document root like:
	// src=images/img.jpg or src=/images/img.jpg
	// not like:
	// src=../images/img.jpg
	$src = preg_replace( &quot;/\.\.+\//&quot;, &quot;&quot;, $src );

	return $src;

}

function get_document_root ($src) {
	if( @file_exists( $_SERVER[&#039;DOCUMENT_ROOT&#039;] . &#039;/&#039; . $src ) ) {
		return $_SERVER[&#039;DOCUMENT_ROOT&#039;];
	}
	// the relative paths below are useful if timthumb is moved outside of document root
	// specifically if installed in wordpress themes like mimbo pro:
	// /wp-content/themes/mimbopro/scripts/timthumb.php
	$paths = array( &#039;..&#039;, &#039;../..&#039;, &#039;../../..&#039;, &#039;../../../..&#039; );
	foreach( $paths as $path ) {
		if( @file_exists( $path . &#039;/&#039; . $src ) ) {
			return $path;
		}
	}

}

?&gt;</description>
		<content:encoded><![CDATA[<p>Bunu da Kullanabilirsiniz..<br />
&lt;?php</p>
<p>// TimThumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks<br />
// <a href="http://code.google.com/p/timthumb/" rel="nofollow">http://code.google.com/p/timthumb/</a></p>
<p>// MIT License: <a href="http://www.opensource.org/licenses/mit-license.php" rel="nofollow">http://www.opensource.org/licenses/mit-license.php</a></p>
<p>/* Parameters allowed: */</p>
<p>// w: width<br />
// h: height<br />
// zc: zoom crop (0 or 1)<br />
// q: quality (default is 75 and max is 100)</p>
<p>// HTML example: </p>
<p>if( !isset( $_REQUEST[ "src" ] ) ) { die( &#8220;no image specified&#8221; ); }</p>
<p>// clean params before use<br />
$src = clean_source( $_REQUEST[ "src" ] );</p>
<p>// set document root<br />
$doc_root = get_document_root($src);</p>
<p>// get path to image on file system<br />
$src = $doc_root . &#8216;/&#8217; . $src;</p>
<p>$new_width = preg_replace( &#8220;/[^0-9]+/&#8221;, &#8220;&#8221;, get_request( &#8216;w&#8217;, 100 ) );<br />
$new_height = preg_replace( &#8220;/[^0-9]+/&#8221;, &#8220;&#8221;, get_request( &#8216;h&#8217;, 100 ) );<br />
$zoom_crop = preg_replace( &#8220;/[^0-9]+/&#8221;, &#8220;&#8221;, get_request( &#8216;zc&#8217;, 1 ) );<br />
$quality = preg_replace( &#8220;/[^0-9]+/&#8221;, &#8220;&#8221;, get_request( &#8217;9&#8242;, 80 ) );</p>
<p>// set path to cache directory (default is ./cache)<br />
// this can be changed to a different location<br />
$cache_dir = &#8216;./cache&#8217;;</p>
<p>// get mime type of src<br />
$mime_type = mime_type( $src );</p>
<p>// check to see if this image is in the cache already<br />
check_cache( $cache_dir, $mime_type );</p>
<p>// make sure that the src is gif/jpg/png<br />
if( !valid_src_mime_type( $mime_type ) ) {<br />
	$error = &#8220;Invalid src mime type: $mime_type&#8221;;<br />
	die( $error );<br />
}</p>
<p>// check to see if GD function exist<br />
if(!function_exists(&#8216;imagecreatetruecolor&#8217;)) {<br />
	$error = &#8220;GD Library Error: imagecreatetruecolor does not exist&#8221;;<br />
	die( $error );<br />
}</p>
<p>if(strlen($src) &amp;&amp; file_exists( $src ) ) {</p>
<p>	// open the existing image<br />
	$image = open_image( $mime_type, $src );<br />
	if( $image === false ) { die( &#8216;Unable to open image : &#8216; . $src ); }		</p>
<p>	// Get original width and height<br />
	$width = imagesx( $image );<br />
	$height = imagesy( $image );</p>
<p>	// don&#8217;t allow new width or height to be greater than the original<br />
	if( $new_width &gt; $width ) { $new_width = $width; }<br />
	if( $new_height &gt; $height ) { $new_height = $height; }</p>
<p>	// generate new w/h if not provided<br />
	if( $new_width &amp;&amp; !$new_height ) {<br />
		$new_height = $height * ( $new_width / $width );<br />
	}<br />
	elseif($new_height &amp;&amp; !$new_width) {<br />
		$new_width = $width * ( $new_height / $height );<br />
	}<br />
	elseif(!$new_width &amp;&amp; !$new_height) {<br />
		$new_width = $width;<br />
		$new_height = $height;<br />
	}</p>
<p>	// create a new true color image<br />
	$canvas = imagecreatetruecolor( $new_width, $new_height );</p>
<p>	if( $zoom_crop ) {</p>
<p>		$src_x = $src_y = 0;<br />
		$src_w = $width;<br />
		$src_h = $height;</p>
<p>		$cmp_x = $width  / $new_width;<br />
		$cmp_y = $height / $new_height;</p>
<p>		// calculate x or y coordinate and width or height of source</p>
<p>		if ( $cmp_x &gt; $cmp_y ) {</p>
<p>			$src_w = round( ( $width / $cmp_x * $cmp_y ) );<br />
			$src_x = round( ( $width &#8211; ( $width / $cmp_x * $cmp_y ) ) / 2 );</p>
<p>		}<br />
		elseif ( $cmp_y &gt; $cmp_x ) {</p>
<p>			$src_h = round( ( $height / $cmp_y * $cmp_x ) );<br />
			$src_y = round( ( $height &#8211; ( $height / $cmp_y * $cmp_x ) ) / 2 );</p>
<p>		}</p>
<p>		imagecopyresampled( $canvas, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h );</p>
<p>	}<br />
	else {</p>
<p>		// copy and resize part of an image with resampling<br />
		imagecopyresampled( $canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );</p>
<p>	}</p>
<p>	// output image to browser based on mime type<br />
	show_image( $mime_type, $canvas, $quality, $cache_dir );</p>
<p>	// remove image from memory<br />
	imagedestroy( $canvas );</p>
<p>} else {</p>
<p>	if( strlen( $src ) ) { echo $src . &#8216; not found.&#8217;; } else { echo &#8216;no source specified.&#8217;; }</p>
<p>}</p>
<p>function show_image ( $mime_type, $image_resized, $quality, $cache_dir ) {</p>
<p>	// check to see if we can write to the cache directory<br />
	$is_writable = 0;<br />
	$cache_file_name = $cache_dir . &#8216;/&#8217; . get_cache_file();        	</p>
<p>	if( touch( $cache_file_name ) ) {<br />
		// give 666 permissions so that the developer<br />
		// can overwrite web server user<br />
		chmod( $cache_file_name, 0666 );<br />
		$is_writable = 1;<br />
	}<br />
	else {<br />
		$cache_file_name = NULL;<br />
		header( &#8216;Content-type: &#8216; . $mime_type );<br />
	}</p>
<p>	if( stristr( $mime_type, &#8216;gif&#8217; ) ) {<br />
		imagegif( $image_resized, $cache_file_name );<br />
	}<br />
	elseif( stristr( $mime_type, &#8216;jpeg&#8217; ) ) {<br />
		imagejpeg( $image_resized, $cache_file_name, $quality );<br />
	}<br />
	elseif( stristr( $mime_type, &#8216;png&#8217; ) ) {<br />
		imagepng( $image_resized, $cache_file_name, ceil( $quality / 10 ) );<br />
	}<br />
	if( $is_writable ) { show_cache_file( $cache_dir, $mime_type ); }<br />
	exit;</p>
<p>}</p>
<p>function get_request( $property, $default = 0 ) {</p>
<p>	if( isset($_REQUEST[$property]) ) {<br />
		return $_REQUEST[$property];<br />
	} else {<br />
		return $default;<br />
	}</p>
<p>}</p>
<p>function open_image ( $mime_type, $src ) {</p>
<p>	if( stristr( $mime_type, &#8216;gif&#8217; ) ) {<br />
		$image = imagecreatefromgif( $src );<br />
	}<br />
	elseif( stristr( $mime_type, &#8216;jpeg&#8217; ) ) {<br />
		@ini_set(&#8216;gd.jpeg_ignore_warning&#8217;, 1);<br />
		$image = imagecreatefromjpeg( $src );<br />
	}<br />
	elseif( stristr( $mime_type, &#8216;png&#8217; ) ) {<br />
		$image = imagecreatefrompng( $src );<br />
	}<br />
	return $image;</p>
<p>}</p>
<p>function mime_type ( $file ) {</p>
<p>    $os = strtolower(php_uname());<br />
	$mime_type = &#8221;;</p>
<p>	// use PECL fileinfo to determine mime type<br />
	if( function_exists( &#8216;finfo_open&#8217; ) ) {<br />
		$finfo = finfo_open( FILEINFO_MIME );<br />
		$mime_type = finfo_file( $finfo, $file );<br />
		finfo_close( $finfo );<br />
	}</p>
<p>	// try to determine mime type by using unix file command<br />
	// this should not be executed on windows<br />
    if( !valid_src_mime_type( $mime_type ) &amp;&amp; !(eregi(&#8216;windows&#8217;, php_uname()))) {<br />
		if( preg_match( &#8220;/freebsd|linux/&#8221;, $os ) ) {<br />
                	$mime_type = trim ( @shell_exec( &#8216;file -bi $file&#8217; ) );<br />
		}<br />
	}</p>
<p>	// use file&#8217;s extension to determine mime type<br />
	if( !valid_src_mime_type( $mime_type ) ) {<br />
		$frags = split( &#8220;\.&#8221;, $file );<br />
		$ext = strtolower( $frags[ count( $frags ) - 1 ] );<br />
		$types = array(<br />
 			&#8216;jpg&#8217;  =&gt; &#8216;image/jpeg&#8217;,<br />
 			&#8216;jpeg&#8217; =&gt; &#8216;image/jpeg&#8217;,<br />
 			&#8216;png&#8217;  =&gt; &#8216;image/png&#8217;,<br />
 			&#8216;gif&#8217;  =&gt; &#8216;image/gif&#8217;<br />
 		);<br />
		if( strlen( $ext ) &amp;&amp; strlen( $types[$ext] ) ) {<br />
			$mime_type = $types[ $ext ];<br />
		}</p>
<p>		// if no extension provided, default to jpg<br />
		if( !strlen( $ext ) &amp;&amp; !valid_src_mime_type( $mime_type ) ) {<br />
			$mime_type = &#8216;image/jpeg&#8217;;<br />
		}<br />
	}<br />
	return $mime_type;</p>
<p>}</p>
<p>function valid_src_mime_type ( $mime_type ) {</p>
<p>	if( preg_match( &#8220;/jpg|jpeg|gif|png/i&#8221;, $mime_type ) ) { return 1; }<br />
	return 0;</p>
<p>}</p>
<p>function check_cache ( $cache_dir, $mime_type ) {</p>
<p>	// make sure cache dir exists<br />
	if( !file_exists( $cache_dir ) ) {<br />
		// give 777 permissions so that developer can overwrite<br />
		// files created by web server user<br />
		mkdir( $cache_dir );<br />
		chmod( $cache_dir, 0777 );<br />
	}</p>
<p>	show_cache_file( $cache_dir, $mime_type );</p>
<p>}</p>
<p>function show_cache_file ( $cache_dir, $mime_type ) {</p>
<p>	$cache_file = $cache_dir . &#8216;/&#8217; . get_cache_file();</p>
<p>	if( file_exists( $cache_file ) ) {</p>
<p>	    if( isset( $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ] ) ) {</p>
<p>			// check for updates<br />
			$if_modified_since = preg_replace( &#8216;/;.*$/&#8217;, &#8221;, $_SERVER[ "HTTP_IF_MODIFIED_SINCE" ] );<br />
			$gmdate_mod = gmdate( &#8216;D, d M Y H:i:s&#8217;, filemtime( $cache_file ) );</p>
<p>			if( strstr( $gmdate_mod, &#8216;GMT&#8217; ) ) {<br />
				$gmdate_mod .= &#8221; GMT&#8221;;<br />
			}</p>
<p>			if ( $if_modified_since == $gmdate_mod ) {<br />
				header( &#8220;HTTP/1.1 304 Not Modified&#8221; );<br />
				exit;<br />
			}</p>
<p>		}</p>
<p>		$fileSize = filesize( $cache_file );</p>
<p>		// send headers then display image<br />
		header( &#8220;Content-Type: &#8221; . $mime_type );<br />
		header( &#8220;Accept-Ranges: bytes&#8221; );<br />
		header( &#8220;Last-Modified: &#8221; . gmdate( &#8216;D, d M Y H:i:s&#8217;, filemtime( $cache_file ) ) . &#8221; GMT&#8221; );<br />
		header( &#8220;Content-Length: &#8221; . $fileSize );<br />
		header( &#8220;Cache-Control: max-age=9999, must-revalidate&#8221; );<br />
		header( &#8220;Etag: &#8221; . md5($fileSize . $gmdate_mod) );<br />
		header( &#8220;Expires: &#8221; . gmdate( &#8220;D, d M Y H:i:s&#8221;, time() + 9999 ) . &#8220;GMT&#8221; );<br />
		readfile( $cache_file );<br />
		exit;</p>
<p>	}</p>
<p>}</p>
<p>function get_cache_file () {</p>
<p>	global $quality;</p>
<p>	static $cache_file;<br />
	if(!$cache_file) {<br />
		$frags = split( &#8220;\.&#8221;, $_REQUEST['src'] );<br />
		$ext = strtolower( $frags[ count( $frags ) - 1 ] );<br />
		if(!valid_extension($ext)) { $ext = &#8216;jpg&#8217;; }<br />
		$cachename = get_request( &#8216;src&#8217;, &#8216;timthumb&#8217; ) . get_request( &#8216;w&#8217;, 100 ) . get_request( &#8216;h&#8217;, 100 ) . get_request( &#8216;zc&#8217;, 1 ) . get_request( &#8217;9&#8242;, 80 );<br />
		$cache_file = md5( $cachename ) . &#8216;.&#8217; . $ext;<br />
	}<br />
	return $cache_file;</p>
<p>}</p>
<p>function valid_extension ($ext) {</p>
<p>	if( preg_match( &#8220;/jpg|jpeg|png|gif/i&#8221;, $ext ) ) return 1;<br />
	return 0;</p>
<p>}</p>
<p>function clean_source ( $src ) {</p>
<p>	// remove http/ https/ ftp<br />
	$src = preg_replace(&#8220;/^((ht|f)tp(s|):\/\/)/i&#8221;, &#8220;&#8221;, $src);<br />
	// remove domain name from the source url<br />
	$src = str_replace($_SERVER["HTTP_HOST"], &#8220;&#8221;, $src);</p>
<p>	//$src = preg_replace( &#8220;/(?:^\/+|\.{2,}\/+?)/&#8221;, &#8220;&#8221;, $src );<br />
	//$src = preg_replace( &#8216;/^\w+:\/\/[^\/]+/&#8217;, &#8221;, $src );</p>
<p>	// don&#8217;t allow users the ability to use &#8216;../&#8217;<br />
	// in order to gain access to files below document root</p>
<p>	// src should be specified relative to document root like:<br />
	// src=images/img.jpg or src=/images/img.jpg<br />
	// not like:<br />
	// src=../images/img.jpg<br />
	$src = preg_replace( &#8220;/\.\.+\//&#8221;, &#8220;&#8221;, $src );</p>
<p>	return $src;</p>
<p>}</p>
<p>function get_document_root ($src) {<br />
	if( @file_exists( $_SERVER['DOCUMENT_ROOT'] . &#8216;/&#8217; . $src ) ) {<br />
		return $_SERVER['DOCUMENT_ROOT'];<br />
	}<br />
	// the relative paths below are useful if timthumb is moved outside of document root<br />
	// specifically if installed in wordpress themes like mimbo pro:<br />
	// /wp-content/themes/mimbopro/scripts/timthumb.php<br />
	$paths = array( &#8216;..&#8217;, &#8216;../..&#8217;, &#8216;../../..&#8217;, &#8216;../../../..&#8217; );<br />
	foreach( $paths as $path ) {<br />
		if( @file_exists( $path . &#8216;/&#8217; . $src ) ) {<br />
			return $path;<br />
		}<br />
	}</p>
<p>}</p>
<p>?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Yazar: hamdi yıldız</title>
		<link>http://www.phpdili.com/php/php-resim-crop.html/comment-page-1#comment-948</link>
		<dc:creator>hamdi yıldız</dc:creator>
		<pubDate>Sun, 01 May 2011 13:42:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpdili.com/?p=172#comment-948</guid>
		<description>merhaba bu  uzun zamandır aradığım bir script fakat kare olan fotolarda işe yarıyor uzun fotolarda uygulayamadım resimler siyah çıkıyor daha gelişmiş bir script biliyormusunuz</description>
		<content:encoded><![CDATA[<p>merhaba bu  uzun zamandır aradığım bir script fakat kare olan fotolarda işe yarıyor uzun fotolarda uygulayamadım resimler siyah çıkıyor daha gelişmiş bir script biliyormusunuz</p>
]]></content:encoded>
	</item>
	<item>
		<title>Yazar: Özgür Özer</title>
		<link>http://www.phpdili.com/php/php-resim-crop.html/comment-page-1#comment-929</link>
		<dc:creator>Özgür Özer</dc:creator>
		<pubDate>Thu, 21 Apr 2011 04:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpdili.com/?p=172#comment-929</guid>
		<description>güzel ve işe yarayabilecek bi fonksiyon. local&#039;de denedim. sorunsuz çalışıyo. ama şöle bi durum var. örnek vermek gerekirse; mesela yüklenen resmin boyutunun 400*300 olmasını istiyorum. kişi 640*480 pixel boyutlarında bi resmi yüklüyo, tamam bunda pek sorun olmuyo. ama 200*700 pixel boyutlarında bi resim yüklendiği zaman resmin üst ve alt bölümleri gidiyo :D biraz daha geliştirilirse güzel bişe olabilir...</description>
		<content:encoded><![CDATA[<p>güzel ve işe yarayabilecek bi fonksiyon. local&#8217;de denedim. sorunsuz çalışıyo. ama şöle bi durum var. örnek vermek gerekirse; mesela yüklenen resmin boyutunun 400*300 olmasını istiyorum. kişi 640*480 pixel boyutlarında bi resmi yüklüyo, tamam bunda pek sorun olmuyo. ama 200*700 pixel boyutlarında bi resim yüklendiği zaman resmin üst ve alt bölümleri gidiyo <img src='http://www.phpdili.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  biraz daha geliştirilirse güzel bişe olabilir&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

