Photo gallery images are now automatically generated at default res and quality.

This commit is contained in:
Stuart Longland 2009-01-26 18:31:18 +10:00
parent aaa78c5888
commit 97c4afdda9
3 changed files with 81 additions and 4 deletions

View File

@ -365,6 +365,9 @@ void photo_handler( struct gallery_info* gallery,
/* Are we asked to show the original image? */
int original = hdf_get_int_value( cgi->hdf, "Query.original", 0 );
/* Are we generating the gallery? */
int generate = hdf_get_int_value( cgi->hdf, "Query.generate", 0 );
int default_width = photo->default_dims.width;
int default_height = photo->default_dims.height;
@ -404,10 +407,12 @@ void photo_handler( struct gallery_info* gallery,
"at %fdeg rotation and %d quality\n",
width, height, rotation, quality);
/* Request image of the specified size */
/* Request image of the specified size
* If we're generating the gallery, we do not resize _yet_.
*/
struct dimensions dims;
char* resized;
if ( original )
if ( original || generate )
resized = construct_path( "s/s", gallery->gallery_name,
photo_name );
else
@ -481,7 +486,10 @@ void photo_handler( struct gallery_info* gallery,
hdf_set_value( cgi->hdf, "photo.next", photo_name );
/* Render the page and display it */
write_template( "photo.cs" );
if ( generate )
write_template( "generator.cs" );
else
write_template( "photo.cs" );
}
void write_template( const char* template_name ) {

69
templates/generator.cs Normal file
View File

@ -0,0 +1,69 @@
<?cs def:html_head() ?>
<style type="text/css">
body {
margin-top: 100px;
}
</style>
<title>Image: <?cs var:html_strip(photo.annotation) ?> (<?cs var:photo.name ?>)</title>
<script lang="type/javascript">
function getData() {
var data = {
CGI: {
ScriptName: '<?cs var:js_escape(CGI.ScriptName) ?>'
},
gallery: {
name: '<?cs var:js_escape(gallery.name) ?>',
title: '<?cs var:js_escape(gallery.title) ?>',
desc: '<?cs var:js_escape(gallery.desc) ?>',
first: '<?cs var:js_escape(gallery.first) ?>',
last: '<?cs var:js_escape(gallery.last) ?>'
},
settings: {
width: <?cs var:settings.width ?>,
height: <?cs var:settings.height ?>,
quality: <?cs var:settings.quality ?>,
rotation: <?cs var:settings.rotation ?>-0
},
photo: {
origwidth: <?cs var:photo.origwidth ?>,
origheight: <?cs var:photo.origheight ?>,
width: <?cs var:photo.width ?>,
height: <?cs var:photo.height ?>,
annotation: "<?cs var:js_escape(photo.annotation) ?>",
thumbnail: "<?cs var:js_escape(photo.thumbnails) ?>",
resized: "<?cs var:js_escape(photo.resized) ?>",
name: "<?cs var:js_escape(photo.name) ?>",
previous: "<?cs var:js_escape(photo.previous) ?>",
next: "<?cs var:js_escape(photo.next) ?>",
zoom: Math.round( 100*(<?cs var:photo.width ?>) /
<?cs var:photo.origwidth ?>)/100
}};
if ( document.data )
data = document.data;
else
document.data = data;
return( data );
}
function advance() {
var nexturl = '<?cs var:CGI.ScriptName ?>/<?cs var:gallery.name ?>/<?cs var:photo.next ?>?generate=1';
if ( nexturl != window.location.href )
window.location.href = nexturl;
else
window.location.href = '<?cs var:CGI.ScriptName ?>/<?cs var:gallery.name ?>';
}
</script>
<script lang="text/javascript" src="<?cs var:uri
?>/templates/lib.js"></script>
<script lang="text/javascript" src="<?cs var:uri
?>/templates/wheellib.js"></script>
<?cs /def ?>
<?cs def:html_body() ?>
<h3>Thumbnail</h3>
<p align="center"><img alt="" src="<?cs var:CGI.ScriptName ?>/<?cs var:gallery.name ?>/<?cs var:photo.name ?>?width=100&amp;height=100&amp;quality=25&amp;redirect=1" /></p>
<h3>Scaled Image</h3>
<p align="center"><img alt="" src="<?cs var:CGI.ScriptName ?>/<?cs var:gallery.name ?>/<?cs var:photo.name ?>?redirect=1" /></p>
<?cs /def ?>
<?cs set:template.bodyargs = 'onload="advance();"' ?>

View File

@ -5,7 +5,7 @@ body {
}
</style>
<title>Image: <?cs var:html_strip(photo.annotation) ?> (<?cs var:photo.name ?>)</title>
<script lang="tyoe/javascript">
<script lang="type/javascript">
function getData() {
var data = {
CGI: {