<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>web2ajax &#187; image</title>
	<atom:link href="http://www.web2ajax.fr/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web2ajax.fr</link>
	<description>Tout l&#039;actualité du Web2.0 et de l&#039;AJAX</description>
	<lastBuildDate>Thu, 10 Feb 2011 00:25:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<atom:link rel='hub' href='http://www.web2ajax.fr/?pushpress=hub'/>
		<item>
		<title>Thumb.php v1.1 : Créer des aperçus d&#8217;image très facilement avec GD</title>
		<link>http://www.web2ajax.fr/2010/03/19/creer-des-apercus-dimage-tres-facilement-avec-gd/</link>
		<comments>http://www.web2ajax.fr/2010/03/19/creer-des-apercus-dimage-tres-facilement-avec-gd/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 15:19:07 +0000</pubDate>
		<dc:creator>Guillaume DE LA RUE</dc:creator>
				<category><![CDATA[gd]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[thumb]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[librairie]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://web2ajax.fr/2008/03/02/creer-des-apercus-dimage-tres-facilement-avec-gd/</guid>
		<description><![CDATA[Très utile pour créer une vignette d'une image, voici un script que j'utilise déjà un pti moment : thumb.phpCe script php permet :• Un resize de qualité• Prise en charge de tous les formats d'image reconnus par GD• Mise en cache des images générées• L'image n'est pas resizée si plus petite que les dimensions fixées• [...]]]></description>
			<content:encoded><![CDATA[<div class="entry">
<div class="content">Très utile pour créer une vignette d'une image, voici un script que j'utilise déjà un pti moment : thumb.php<br><br>Ce script php permet :<br><br>• Un resize de qualité<br>• Prise en charge de tous les formats d'image reconnus par GD<br>• Mise en cache des images générées<br>• L'image n'est pas resizée si plus petite que les dimensions fixées<br>• Une manière sûre de ne pas dépasser une dimension fixée<br><br>Voici comment utiliser le script dans votre page HTML :<br><br>[sourcecode]<br>&lt;img src=&quot;thumb.php?i=chemin_image&amp;amp;w=150&amp;amp;h=150&quot;&gt;<br>[/sourcecode]<br><br>i => Chemin de l'image sur le serveur<br>w => Largeur maximale<br>h => Hauteur maximale<br>iar => 0 aspect ratio conserved / 1 picture deformed<br><br>Pour éviter de déformer l'image, je vous conseille d'utiliser dans tous les cas une hauteur égale à la largeur.<br><br>Le script :<br><br>[sourcecode]<br>&lt;?php<br>#@<br>#@ Load a picture and take few parameters<br>#@ Build cache file for thumbnail view<br>#@ <br>#@ Created by Guillaume DE LA RUE &lt;http://web2ajax.fr/&gt;<br>#@ Version 1.1 : 2010/03/19<br>#@<br><br>#@<br>#@ Local Function to get extension<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">function _getExtension($file_name) {<br>	$file_infos = pathinfo($file_name);<br>	return '.'.$file_infos['extension'] ;<br>}<br>	<br>#@<br>#@ Config<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">$cache_dir = 'tmp/thumbs/' ;<br><br>#@<br>#@ Get url params<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">$width 			= (int) $_GET['w'] ;<br>$height			= (int) $_GET['h'] ;<br>$image_file		= $_GET['i'];<br>$image_quality	= (int) $_GET['q'] ;<br>$cache_force	= $_GET['nocache'] ;<br><br>#@<br>#@ Customize the image url<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">$image_file = urldecode($image_file) ;<br>$image_file = @reset(@explode('?', $image_file)) ;<br><br>#@<br>#@ Set vars<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">$image_file_extension 	= _getExtension($image_file, true) ;<br>$image_file_basename 	= basename($image_file, $image_file_extension) ;	// Filename without extension '.jpg'<br>$thumb_file				= $image_file ;<br><br>#@<br>#@ Infos in image_file<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">## Get md5 of files location<br>$thumb_file_md5 = md5($thumb_file).&quot;_&quot;.$width.&quot;_&quot;.$height.&quot;_&quot;.$_GET['iar'] ;<br>$hex_folder = substr($thumb_file_md5, 0, 2).'/' ;<br>$img_thumb = $cache_dir.$hex_folder.$thumb_file_md5.$image_file_extension ;<br><br>// Create a thumb from image<br>function create_thumb($src, $dest, $width = 0, $height = 0, $deform = false, $no_img = './assets/img/trans.gif' ) {<br>	<br>	## Make directory<br>	@mkdir(dirname($dest)) ;<br>	<br>	## Get infos on file with exif<br>	list($width_original, $height_original, $image_mime) = @getimagesize($src);  <br>	<br>	// Init w &amp;amp; h<br>	$_w = ( $width ? $width : $width_original ) ;<br>	$_h = ( $height ? $height : $height_original ) ;<br>	<br>	// If error <br>	if ( ! $image_mime ) {<br>		$src = $no_img ;<br>		list($width_original, $height_original, $image_mime) = getimagesize($src);  <br>	}<br>	<br>	## Detect Portait( =&gt; 0) / paysage ( =&gt; 1)<br>	if ( $width_original &lt;= $height_original ) {<br>		$image_type = 0 ;<br>	} else {<br>		$image_type = 1 ;<br>	}<br>	<br>	## If width or height is empty =&gt; auto<br>	if ( $_w == 0 &amp;amp;&amp;amp; $_h &gt; 0 ) {<br>		$_w = $width_original * ($_h / $height_original ) ;<br>	} else if ( $width &gt; 0 &amp;amp;&amp;amp; $height == 0 ) { <br>		$_h = $height_original * ($_w / $width_original ) ;<br>	} else {<br>		$is_error = true ;<br>	}<br>			<br>	## Define best size to thumb depending params<br>	if ( $image_type == 0 ) {<br>		$best_height 	= $_h ;<br>		if ( $height_original ) $best_width 	= (int) ( $width_original * ($_h / $height_original ) ) ;<br>	} else {<br>		$best_width 	= $_w ;<br>		if ( $width_original ) $best_height 	= (int) ( $height_original * ( $_w / $width_original ) ) ;		<br>	}<br>	<br>	## If picture is little than wanted =&gt; don't stretch it, juste create a standard thumbnail<br>	if ( $width_original &lt; $_w &amp;amp;&amp;amp; $height_original &lt; $_h ) {<br>		$best_width = $width_original ;<br>		$best_height = $height_original ;		<br>	} <br>	<br>	## If 'iar' is setted =&gt; do desired stretching and no more<br>	if ( $deform == &quot;1&quot; ) {<br>		$best_width = (int) $width ;<br>		$best_height = (int) $height ;<br>	}<br>		<br>	// set image type, blending and set functions for gif, jpeg and png  <br>	switch($image_mime){  <br>	  case IMAGETYPE_PNG:  $img = 'png';  $blending = false; break;  <br>	  case IMAGETYPE_GIF:  $img = 'gif';  $blending = true;  break;  <br>	  case IMAGETYPE_JPEG: $img = 'jpeg'; break;  <br>	}  <br>	$imagecreate = &quot;imagecreatefrom$img&quot;;  <br>	$imagesave   = &quot;image$img&quot;;  <br>	<br>	// initialize image from the file  <br>	$image1 = $imagecreate($src);  <br>	<br>	// create a new true color image with dimensions $width2 and $height2  <br>	$image2 = imagecreatetruecolor($best_width, $best_height);  <br>	<br>	// preserve transparency for PNG and GIF images  <br>	if ($img == 'png' || $img == 'gif'){  <br>	  // allocate a color for thumbnail  <br>	  $background = imagecolorallocate($image2, 0, 0, 0);  <br>	  // define a color as transparent  <br>	  imagecolortransparent($image2, $background);  <br>	  // set the blending mode for thumbnail  <br>	  imagealphablending($image2, $blending);  <br>	  // set the flag to save alpha channel  <br>	  imagesavealpha($image2, true);  <br>	}  <br>	<br>	// save thumbnail image to the file  <br>	imagecopyresampled($image2, $image1, 0, 0, 0, 0, $best_width, $best_height, $width_original, $height_original);  <br>	$imagesave($image2, $dest, ($img == 'jpeg' ? 100 : true));  	<br>	ImageDestroy($image2); <br>}<br><br>#@<br>#@ If thumbnail doesn't exists create it !<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">if ( ! file_exists($img_thumb) || $cache_force == &quot;true&quot;) <br>	create_thumb($image_file, $img_thumb, $width, $height, $deform = $_GET['iar']) ;<br>else <br><br>// -&gt; Get the type mime of the image<br>list($width_original, $height_original, $image_mime) = getimagesize($img_thumb);  <br>switch($image_mime){  <br>  case IMAGETYPE_PNG:  $image_mime = 'image/png';  break;  <br>  case IMAGETYPE_GIF:  $image_mime = 'image/gif';  break;  <br>  case IMAGETYPE_JPEG: $image_mime = 'image/jpeg'; break;  <br>}  <br><br>#@<br>#@ FORCE TO CACHE IMAGE<br>#@ <div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content"><div class="content">$img_content = file_get_contents($img_thumb) ;<br><br>// not sure if this stuff is really needed, but works:<br>@header(&quot;Cache-Control: private, max-age=10800, pre-check=10800&quot;);<br>@header(&quot;Pragma: private&quot;);<br>@header(&quot;Expires: &quot; . date(DATE_RFC822,strtotime(&quot;+100 day&quot;)));<br>// the browser will send a $_SERVER['HTTP_IF_MODIFIED_SINCE'] <br>// option 1, you can just check if the browser is sendin this<br>if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){<br>  // if the browser has a cached version of this image, send 304<br>  @header('Last-Modified: '.$_SERVER['HTTP_IF_MODIFIED_SINCE'],true,304);<br>  exit;<br>}<br>// option 2, if you have a file to base your mod date off:<br>if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) <br>       &amp;amp;&amp;amp; <br>  (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($img_file))) {<br>  // send the last mod time of the file back<br>  @header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($img_file)).' GMT', <br>  true, 304);<br>  exit;<br>}<br><br>// and here we send the image to the browse with all the stuff<br>// required for tell it to cache<br>$image_infos 	= @getimagesize($cache_dir.$thumb_file_md5.$image_file_extension) ;<br>@header(&quot;Content-type: &quot;.$image_mime); <br>@header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($img_file)) . ' GMT');<br>@header(&quot;Content-Length: &quot;.strlen($img_content));<br>echo $img_content;<br>?&gt;<br>[/sourcecode]</div></div><div class="buttons"></div>
	<div class="clearfix"></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.web2ajax.fr/2010/03/19/creer-des-apercus-dimage-tres-facilement-avec-gd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 5.682 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-04 12:26:35 -->
<!-- Compression = gzip -->
