=$object['IMG_W'])&&($height>=$object['IMG_H'])) return $object; $thumbstring=":Galerías-II:thumbnail:".$object['FILE'].":$width x $height>"; $thumbs_ext=(defined('__GAL_THUMBS_FORCE_EXT'))?__GAL_THUMBS_FORCE_EXT:$object['EXT']; $thumbfile=h_cache_get_file_from_string($thumbstring, $thumbs_dir).'.'.$thumbs_ext; s_log("thumbfile: $thumbfile"); if(!h_fs_check_dir($thumbfile)) return __GAL_THUMB_RESULT_ERROR; if(file_exists($thumbfile)) { $thumb_obj=h_fs_get_object_from_file($thumbfile,'',1,'gal_get_extra_object_from_file'); if($create&&is_array($thumb_obj)) { if($object['MTIME']>$thumb_obj['MTIME']) $thumb_obj=gal_create_thumb($object, $thumbfile, $width, $height); } } else { if($create) $thumb_obj=gal_create_thumb($object, $thumbfile, $width, $height); else return __GAL_THUMB_RESULT_ERROR; } if(is_array($thumb_obj)) return $thumb_obj; if((strlen($thumb_obj)>1)&&file_exists($thumb_obj)) return gal_get_object_from_file($thumb_obj); s_log("thumb_obj: $thumb_obj"); return $thumb_obj; } } function gal_send_image_object($object) { if(!is_array($object)) return; //Output to Browser if(empty($object['MIME'])) return; header("Content-type: ".$object['MIME']); #header("Refresh: 3; URL=$SCRIPT_NAME?GAL_IMG_FILE=$GAL_IMG_FILE"); // test for non-blocking cache $file=basename($object['FILE']); if($file) header("Content-Disposition: attachment; filename=$file"); if(!file_exists($object['FULL_FILE'])) return; readfile($object['FULL_FILE']); } function gal_get_thumb_size_from_file($file, $dir, $width, $height, $thumbs_dir=__GAL_THUMBS_DIR) { if((!$width)||(!$height)) return; $thumb=gal_get_thumb_from_file($file, $dir, $width, $height, $thumbs_dir, 0); if(is_array($thumb)) { if($thumb['IMG_SIZE']) return $thumb['IMG_SIZE']; if($thumb['IMG_W']&&$thumb['IMG_H']) return 'width='.$thumb['IMG_W'].' height='.$thumb['IMG_H']; } $object=h_fs_get_object_from_file($file,$dir,0,'gal_get_extra_object_from_file'); return gal_get_thumb_size_from_object($object, $width, $height); } function gal_get_thumb_size_from_object($object, $width, $height) { if((!$width)||(!$height)) return; if((!$object['IMG_W'])||(!$object['IMG_H'])) return; if(($object['IMG_W']<=$width)&&($object['IMG_H']<=$height)) return 'width='.$object['IMG_W'].' height='.$object['IMG_H']; $wscale=$object['IMG_W']/$width; $hscale=$object['IMG_H']/$height; if($wscale>$hscale) return 'width='.$width.' height='.($object['IMG_H']/$wscale); if($hscale>$wscale) return 'width='.($object['IMG_W']/$hscale).' height='.$height; return "width=$width height=$height"; } #--------------------------------------------------------------------- function gal_create_thumb($object, $thumbfile, $width, $height) { if(!$object['MIME']) return __GAL_THUMB_RESULT_DEFAULT; $mime=explode('/',$object['MIME']); $small_function='gal_create_thumb_from_mime_'.$mime[0]; $large_function=$small_function.'_'.$mime[1]; if(function_exists($large_function)) return $large_function($object, $thumbfile, $width, $height); if(function_exists($small_function)) return $small_function($object, $thumbfile, $width, $height); return __GAL_THUMB_RESULT_DEFAULT; } function gal_get_thumb_from_template($template_prefix, $name, $template_dir='') { $default_img_file=h_template_probe_name($template_prefix."-$name",$template_dir,'jpg gif png jpeg'); s_log("Default Img: $default_img_file - ".strlen($default_img_file),0,0,3); //$img_object=h_fs_get_object_from_file($default_img_file, '', 2, 'gal_get_extra_object_from_file'); //if(is_array($img_object)) // return $img_object; return $default_img_file; } #--------------------------------------------------------------------- // Mime drivers - should go to a different file when too many function gal_create_thumb_from_mime_image_jpeg($object, $thumbfile, $width, $height) { // Here we must use the native JPEG functions (GD) // We can borrow from Acalli s_log('image/jpeg thumbnail driver',0,0,3); return gal_create_thumb_from_mime_image($object, $thumbfile, $width, $height); } function gal_create_thumb_from_mime_image($object, $thumbfile, $width, $height) { $result=gal_create_thumb_with_Image_Magick($object, $thumbfile, $width, $height); if($result) return __GAL_THUMB_RESULT_ERROR; return $thumbfile; } function gal_create_thumb_with_Image_Magick($object, $thumbfile, $width, $height) { $command=__GAL_CONVERT.' -geometry '.$width.'x'.$height.' '; $command.=$object['FULL_FILE'].' '.$thumbfile; $command=escapeshellcmd($command); s_log("command: $command",0,0,0); exec($command,$output,$result); if($result) s_log_error("Command $command execution error: $result"); return $result; } #--------------------------------------------------------------------- } //__GAL_THUMBNAILS__ ?>