Galeria d’imatges

Carrer Caldes 1, Sant Cugat - Barcelona - España - Tel: 93.675.64.27 / 671.687.814 - info@guixota.com
$lastmod){ $lastmod = $when; } } # end if ft }# end elseif } #end while closedir($dh); return array("name" => $dir, "lastmod" => $lastmod, "images" => $imgs, "dirs" => $dirs); } #end load_dir function getValidExtension($file){ foreach(array("jpg","png","gif") as $pft){ $ext = strtolower(substr($file, - strlen($pft))); if($ext == $pft){ return $ext; } } return 0; } function getJSON($dir){ $is = Array(); $imgs = $dir['images']; foreach($imgs as $i => $m){ $comma = ', '; # readability $isize = GetImageSize($i,$info); $ipi = "{}"; if (isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); $ipi = array(); foreach($iptc as $skey => $sval){ $sipi = array(); foreach($sval as $k => $v){ $v = htmlentities($v); $v = addslashes($v); $v = str_replace("\n",'\n',$v); $v = str_replace("\r",'\r',$v); $sipi[] = "\"$k\": \"$v\""; } $ipi[] = "\"$skey\": { " . implode($comma,$sipi) . " }"; } $ipi = '{' . implode($comma,$ipi) . '}'; } $exifi = "{}"; if(function_exists("exif_read_data") && getValidExtension($i) == "jpg"){ $exifdata = exif_read_data($i,'ANY_TAG',1); if($exifdata){ $exifi = array(); foreach($exifdata as $section => $secdata){ $sres = array(); foreach($secdata as $k => $v) $v = htmlentities($v); $v = addslashes($v); $v = str_replace("\n",'\n',$v); $v = str_replace("\r",'\r',$v); $sres[]= "\"$k\": \"$v\""; $exifi[] = "\"$section\": { " . implode($comma,$sres) ." }"; } $exifi = "{" . implode($comma,$exifi) . "}"; } } $is[] = '{ "url": "' . $i .'", ' . '"date": ' . $m . $comma . '"width": ' . $isize[0] . $comma . '"height": ' . $isize[1] . $comma . '"filesize": ' . filesize($i) . $comma . '"iptc": ' . $ipi . $comma . '"exif": ' . $exifi . '}'; } $json = '({' . "\"name\" : \"" . $dir['name'] . "\", \n" . "\"images\" : [\n" . implode(",\n",$is) . "\n]" . '})'; return $json; } function pyxyResize(){ $filename = basename($_REQUEST['file']); $width = isset($_REQUEST['width']) ? $_REQUEST['width'] : 160; $height = isset($_REQUEST['height']) ? $_REQUEST['height'] : 160; $dim = Array($width,$height); doResize($filename,$dim); } function doResize($filename,$dimensions,$method="ImageCopyResized"){ IfModSince(filemtime($filename)); $olddimensions = GetImageSize($filename); $wide = $olddimensions[0]; $high = $olddimensions[1]; $dimensions = scaledim($olddimensions,$dimensions); $newW = $dimensions[0]; $newH = $dimensions[1]; if($wide < $newW && $high < $newH){ header("Location: $filename"); exit; # redirect to file if it's small enough already } if(function_exists("string_exif_thumbnail") && getValidExtension($file) == "jpg"){ $thumb = exif_thumbnail($filename, $xWidth,$xHeight,$xImageType); if($xWidth < $newW && $xHeight < $newH){ header("Cache-control: public, max-age=86400"); header("Content-type: " . image_type_to_mime_type($xImageType)); echo($thumb); } } $img = loadImage($filename); $newimg = imageCreateTrueColor( $newW, $newH ); $rrf = 4; # resize-resample factor if($wide > $newW * $rrf || $high > $newH * $rrf){ $tempimg = imageCreateTrueColor( $newW * $rrf, $newH * $rrf ); ImageCopyResized( $tempimg, $img, 0, 0, 0, 0, $newW * $rrf, $newH * $rrf, $wide, $high); ImageCopyResampled($newimg, $tempimg, 0, 0, 0, 0, $newW, $newH, $newW * $rrf, $newH * $rrf); ImageDestroy($tempimg); } else { ImageCopyResampled($newimg, $img, 0, 0, 0, 0, $newW, $newH ,$wide, $high); } //$method($newimg, $img, 0, 0, 0, 0, $newW, $newH ,$wide, $high); ImageDestroy ($img); ob_start(); ImageJpeg($newimg,'',60); $ImageData = ob_get_contents(); $ImageDataLength = ob_get_length(); ob_end_clean(); ImageDestroy($newimg); header("Cache-control: public, max-age=86400"); header('Content-Type: image/jpeg'); header("Content-Length: " . $ImageDataLength); echo $ImageData; } function loadImage($filename){ $ext = getValidExtension($filename); if($ext == "gif"){ return ImageCreateFromGIF($filename); } elseif($ext == "jpg" || $ext == "jpeg"){ return ImageCreateFromJPEG($filename); } elseif($ext == "png") { return ImageCreateFromPNG($filename); } } function scaledim($from,$to){ $newW = $wide = $from[0]; $newH = $high = $from[1]; $maxW = $to[0]; $maxH = $to[1]; if($newH < $maxH && $newW < $maxW){ return $from; } $wrat = $maxW / $wide; $hrat = $maxH / $high; if($newH > $maxH){ $newH = $high * $hrat; $newW = $wide * $hrat; } if($newW > $maxW) { #check both dimensions $newH = $high * $wrat; $newW = $wide * $wrat; } $newH = floor($newH); $newW = floor($newW); $dim[0] = $newW; $dim[1] = $newH; return $dim; } function IfModSince($lastmod){ if ($lastmod) { $mself = filemtime($_SERVER['SCRIPT_FILENAME']) ; if($mself > $lastmod) $lastmod = $mself; /* if(file_exists('pyxy.pref.inc')){ $mpref = filemtime('pyxy.pref.inc'); if($mpref > $lastmod) $lastmod = $mpref; } */ $cond = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : 0; if ($cond and $_SERVER['REQUEST_METHOD'] == 'GET' and strtotime($cond) >= $lastmod) { header('HTTP/1.0 304 Not Modified'); exit; } #end if cond header('Last-Modified: ' . date('r',$lastmod)); } #end if lastmod } # end IfModSince function getTitle(){ $x = explode("/",$_SERVER['SCRIPT_FILENAME']); $x = str_replace('_', ' ', $x); $x = $x[sizeof($x) - 2]; $x[0] = strtoupper($x[0]); return $x; }