Fit-to-size by default
This commit is contained in:
parent
2c076d219e
commit
475f75178e
16
Makefile
16
Makefile
@ -1,23 +1,25 @@
|
||||
.PHONY: clean
|
||||
CS_PATH=/usr
|
||||
MAGICK_CFLAGS=$(shell Wand-config --cflags --cppflags)
|
||||
MAGICK_LDFLAGS=$(shell Wand-config --ldflags --libs)
|
||||
CFLAGS+=$(shell Wand-config --cflags --cppflags)
|
||||
LDFLAGS+=$(shell Wand-config --ldflags --libs)
|
||||
|
||||
CS_CFLAGS=-I$(CS_PATH)/include/ClearSilver
|
||||
CFLAGS+=-I$(CS_PATH)/include/ClearSilver -DEBUG -g
|
||||
|
||||
CFLAGS+=$(shell pkg-config --cflags json)
|
||||
LDFLAGS+=$(shell pkg-config --libs json)
|
||||
OBJS=obj/main.o obj/util.o obj/galleries.o obj/gallery.o obj/varray.o \
|
||||
obj/photo.o $(CS_PATH)/lib/libneo_cgi.a $(CS_PATH)/lib/libneo_cs.a \
|
||||
obj/photo.o obj/hdf-json.o \
|
||||
$(CS_PATH)/lib/libneo_cgi.a $(CS_PATH)/lib/libneo_cs.a \
|
||||
$(CS_PATH)/lib/libneo_utl.a
|
||||
|
||||
gallery.cgi: $(OBJS)
|
||||
$(CC) -o $@ $(OBJS) $(MAGICK_LDFLAGS)
|
||||
$(CC) -o $@ $(OBJS) $(LDFLAGS)
|
||||
obj:
|
||||
mkdir obj
|
||||
|
||||
obj/%.o: src/%.c include/%.h obj
|
||||
$(CC) -DCOMPILESTAMP='"$(shell date "+%Y-%m-%d %H:%M:%S %z" )"' \
|
||||
$(CFLAGS) $(MAGICK_CFLAGS) $(CS_CFLAGS) \
|
||||
-I include -o $@ -c $<
|
||||
$(CFLAGS) -I include -o $@ -c $<
|
||||
|
||||
clean:
|
||||
rm -fr obj gallery.cgi
|
||||
|
@ -20,6 +20,13 @@ CGI* cgi;
|
||||
CSPARSE* cstemp;
|
||||
char* cstemp_dir;
|
||||
|
||||
/* Output mode. This is set by main() and defines the mode of output for all
|
||||
* functions defined.
|
||||
*/
|
||||
#define OUTPUT_HTML 0
|
||||
#define OUTPUT_JSON 1
|
||||
char output_mode = OUTPUT_HTML;
|
||||
|
||||
/* Entry point into entire webapp */
|
||||
int main( int argc, char** argv );
|
||||
|
||||
@ -42,4 +49,7 @@ void photo_handler(
|
||||
void action_handler( char* action_name, /* Name of action to perform */
|
||||
struct vararray* path_info );
|
||||
|
||||
/* Write a template out */
|
||||
void write_template( const char* template_name );
|
||||
|
||||
#endif
|
||||
|
65
src/main.c
65
src/main.c
@ -10,6 +10,8 @@
|
||||
#include <string.h>
|
||||
#include <photo.h>
|
||||
#include <ClearSilver/ClearSilver.h>
|
||||
#include <json/json.h>
|
||||
#include <hdf-json.h>
|
||||
|
||||
/* Entry point into entire webapp */
|
||||
int main( int argc, char** argv ) {
|
||||
@ -39,6 +41,11 @@ int main( int argc, char** argv ) {
|
||||
|
||||
hdf_set_value( cgi->hdf, "uri", get_cgiuri() );
|
||||
|
||||
/* Detect JSON mode */
|
||||
if ( argc > 1 )
|
||||
if ( strcmp( argv[1], "json" ) == 0 )
|
||||
output_mode = OUTPUT_JSON;
|
||||
|
||||
/* Parse the PATH_INFO variable */
|
||||
struct vararray* path_info = create_vararray( NULL, 0, NULL, NULL );
|
||||
char* raw_path_info = getenv("PATH_INFO");
|
||||
@ -117,27 +124,24 @@ void gallery_index() {
|
||||
|
||||
size_t i;
|
||||
for ( i = 0; i < list->length; i++ ) {
|
||||
snprintf( name, sizeof( name ), "gallery.%d.name", i );
|
||||
snprintf( name, sizeof( name ),
|
||||
"gallery.%d.name", i );
|
||||
hdf_set_value( cgi->hdf, name,
|
||||
list->gallery[i]->gallery_name );
|
||||
list->gallery[i]->gallery_name );
|
||||
|
||||
snprintf( name, sizeof( name ), "gallery.%d.title", i );
|
||||
snprintf( name, sizeof( name ),
|
||||
"gallery.%d.title", i );
|
||||
hdf_set_value( cgi->hdf, name,
|
||||
list->gallery[i]->gallery_title );
|
||||
list->gallery[i]->gallery_title );
|
||||
|
||||
snprintf( name, sizeof( name ), "gallery.%d.desc", i );
|
||||
snprintf( name, sizeof( name ),
|
||||
"gallery.%d.desc", i );
|
||||
hdf_set_value( cgi->hdf, name,
|
||||
list->gallery[i]->gallery_desc );
|
||||
list->gallery[i]->gallery_desc );
|
||||
}
|
||||
|
||||
/* Render the page and display it */
|
||||
char* template = construct_path( "s/s", cstemp_dir, "index.cs" );
|
||||
dprintf( "gallery_index: using template %s\n", template );
|
||||
NEOERR* err = cgi_display( cgi, template );
|
||||
if ( err != STATUS_OK ) {
|
||||
cgi_neo_error(cgi, err);
|
||||
nerr_log_error(err);
|
||||
}
|
||||
write_template( "index.cs" );
|
||||
}
|
||||
|
||||
/* Gallery main handler */
|
||||
@ -196,13 +200,7 @@ void gallery_handler( struct gallery_info* gallery,
|
||||
}
|
||||
|
||||
/* Render the page and display it */
|
||||
char* template = construct_path( "s/s", cstemp_dir, "gallery.cs" );
|
||||
dprintf( "gallery_handler: using template %s\n", template );
|
||||
NEOERR* err = cgi_display( cgi, template );
|
||||
if ( err != STATUS_OK ) {
|
||||
cgi_neo_error(cgi, err);
|
||||
nerr_log_error(err);
|
||||
}
|
||||
write_template( "gallery.cs" );
|
||||
}
|
||||
|
||||
/* Action pages handler */
|
||||
@ -280,12 +278,23 @@ void photo_handler( struct gallery_info* gallery,
|
||||
hdf_set_value( cgi->hdf, "photo.next", "#" );
|
||||
|
||||
/* Render the page and display it */
|
||||
char* template = construct_path( "s/s", cstemp_dir, "photo.cs" );
|
||||
dprintf( "photo_handler: using template %s\n", template );
|
||||
NEOERR* err = cgi_display( cgi, template );
|
||||
if ( err != STATUS_OK ) {
|
||||
cgi_neo_error(cgi, err);
|
||||
nerr_log_error(err);
|
||||
}
|
||||
|
||||
write_template( "photo.cs" );
|
||||
}
|
||||
|
||||
void write_template( const char* template_name ) {
|
||||
if ( output_mode == OUTPUT_JSON ) {
|
||||
/* Ignore the template name, we were asked for JSON data */
|
||||
struct json_object* cgi_json =
|
||||
hdf_obj_to_json( NULL, cgi->hdf );
|
||||
puts("Content-Type: text/plain\n\n");
|
||||
puts( json_object_to_json_string( cgi_json ) );
|
||||
} else {
|
||||
char* template = construct_path( "s/s", cstemp_dir, template_name );
|
||||
NEOERR* err = cgi_display( cgi, template );
|
||||
if ( err != STATUS_OK ) {
|
||||
cgi_neo_error(cgi, err);
|
||||
nerr_log_error(err);
|
||||
}
|
||||
free( template );
|
||||
}
|
||||
}
|
||||
|
11
src/photo.c
11
src/photo.c
@ -348,8 +348,17 @@ char* resize_photo( struct photo_meta* dest,
|
||||
height = dest->size.height;
|
||||
} else if ( width == 0 ) {
|
||||
width = (unsigned int)((double)height * aspect_ratio);
|
||||
} else {
|
||||
} else if ( height == 0 ) {
|
||||
height = (unsigned int)((double)width / aspect_ratio);
|
||||
} else {
|
||||
/* We're given both. Scale the photo to fit within this area */
|
||||
unsigned int s_width = (unsigned int)
|
||||
((double)height * aspect_ratio);
|
||||
if ( s_width > width )
|
||||
height = (unsigned int)
|
||||
((double)width / aspect_ratio);
|
||||
else
|
||||
width = s_width;
|
||||
}
|
||||
|
||||
dprintf( "resize_photo: dimensions %dx%d\n", width, height );
|
||||
|
Loading…
Reference in New Issue
Block a user