Fit-to-size by default
This commit is contained in:
parent
2c076d219e
commit
475f75178e
16
Makefile
16
Makefile
@ -1,23 +1,25 @@
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
CS_PATH=/usr
|
CS_PATH=/usr
|
||||||
MAGICK_CFLAGS=$(shell Wand-config --cflags --cppflags)
|
CFLAGS+=$(shell Wand-config --cflags --cppflags)
|
||||||
MAGICK_LDFLAGS=$(shell Wand-config --ldflags --libs)
|
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 \
|
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
|
$(CS_PATH)/lib/libneo_utl.a
|
||||||
|
|
||||||
gallery.cgi: $(OBJS)
|
gallery.cgi: $(OBJS)
|
||||||
$(CC) -o $@ $(OBJS) $(MAGICK_LDFLAGS)
|
$(CC) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
obj:
|
obj:
|
||||||
mkdir obj
|
mkdir obj
|
||||||
|
|
||||||
obj/%.o: src/%.c include/%.h obj
|
obj/%.o: src/%.c include/%.h obj
|
||||||
$(CC) -DCOMPILESTAMP='"$(shell date "+%Y-%m-%d %H:%M:%S %z" )"' \
|
$(CC) -DCOMPILESTAMP='"$(shell date "+%Y-%m-%d %H:%M:%S %z" )"' \
|
||||||
$(CFLAGS) $(MAGICK_CFLAGS) $(CS_CFLAGS) \
|
$(CFLAGS) -I include -o $@ -c $<
|
||||||
-I include -o $@ -c $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr obj gallery.cgi
|
rm -fr obj gallery.cgi
|
||||||
|
@ -20,6 +20,13 @@ CGI* cgi;
|
|||||||
CSPARSE* cstemp;
|
CSPARSE* cstemp;
|
||||||
char* cstemp_dir;
|
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 */
|
/* Entry point into entire webapp */
|
||||||
int main( int argc, char** argv );
|
int main( int argc, char** argv );
|
||||||
|
|
||||||
@ -42,4 +49,7 @@ void photo_handler(
|
|||||||
void action_handler( char* action_name, /* Name of action to perform */
|
void action_handler( char* action_name, /* Name of action to perform */
|
||||||
struct vararray* path_info );
|
struct vararray* path_info );
|
||||||
|
|
||||||
|
/* Write a template out */
|
||||||
|
void write_template( const char* template_name );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
65
src/main.c
65
src/main.c
@ -10,6 +10,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <photo.h>
|
#include <photo.h>
|
||||||
#include <ClearSilver/ClearSilver.h>
|
#include <ClearSilver/ClearSilver.h>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <hdf-json.h>
|
||||||
|
|
||||||
/* Entry point into entire webapp */
|
/* Entry point into entire webapp */
|
||||||
int main( int argc, char** argv ) {
|
int main( int argc, char** argv ) {
|
||||||
@ -39,6 +41,11 @@ int main( int argc, char** argv ) {
|
|||||||
|
|
||||||
hdf_set_value( cgi->hdf, "uri", get_cgiuri() );
|
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 */
|
/* Parse the PATH_INFO variable */
|
||||||
struct vararray* path_info = create_vararray( NULL, 0, NULL, NULL );
|
struct vararray* path_info = create_vararray( NULL, 0, NULL, NULL );
|
||||||
char* raw_path_info = getenv("PATH_INFO");
|
char* raw_path_info = getenv("PATH_INFO");
|
||||||
@ -117,27 +124,24 @@ void gallery_index() {
|
|||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
for ( i = 0; i < list->length; 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,
|
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,
|
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,
|
hdf_set_value( cgi->hdf, name,
|
||||||
list->gallery[i]->gallery_desc );
|
list->gallery[i]->gallery_desc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Render the page and display it */
|
/* Render the page and display it */
|
||||||
char* template = construct_path( "s/s", cstemp_dir, "index.cs" );
|
write_template( "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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gallery main handler */
|
/* Gallery main handler */
|
||||||
@ -196,13 +200,7 @@ void gallery_handler( struct gallery_info* gallery,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Render the page and display it */
|
/* Render the page and display it */
|
||||||
char* template = construct_path( "s/s", cstemp_dir, "gallery.cs" );
|
write_template( "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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Action pages handler */
|
/* Action pages handler */
|
||||||
@ -280,12 +278,23 @@ void photo_handler( struct gallery_info* gallery,
|
|||||||
hdf_set_value( cgi->hdf, "photo.next", "#" );
|
hdf_set_value( cgi->hdf, "photo.next", "#" );
|
||||||
|
|
||||||
/* Render the page and display it */
|
/* Render the page and display it */
|
||||||
char* template = construct_path( "s/s", cstemp_dir, "photo.cs" );
|
write_template( "photo.cs" );
|
||||||
dprintf( "photo_handler: using template %s\n", template );
|
}
|
||||||
NEOERR* err = cgi_display( cgi, template );
|
|
||||||
if ( err != STATUS_OK ) {
|
void write_template( const char* template_name ) {
|
||||||
cgi_neo_error(cgi, err);
|
if ( output_mode == OUTPUT_JSON ) {
|
||||||
nerr_log_error(err);
|
/* 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;
|
height = dest->size.height;
|
||||||
} else if ( width == 0 ) {
|
} else if ( width == 0 ) {
|
||||||
width = (unsigned int)((double)height * aspect_ratio);
|
width = (unsigned int)((double)height * aspect_ratio);
|
||||||
} else {
|
} else if ( height == 0 ) {
|
||||||
height = (unsigned int)((double)width / aspect_ratio);
|
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 );
|
dprintf( "resize_photo: dimensions %dx%d\n", width, height );
|
||||||
|
Loading…
Reference in New Issue
Block a user