summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordan <[email protected]>2023-03-12 23:51:02 -0400
committerdan <[email protected]>2023-03-12 23:51:02 -0400
commit5f1f3fa55e998cd6021af7614275c3a1afb8b501 (patch)
treecedc774f37d3c65ee27c97f68367f62c3456883a
parentdc363d950e8d3b3c05f4cd0062d9dd59cc74e37e (diff)
download54-5f1f3fa55e998cd6021af7614275c3a1afb8b501.tar.gz
54-5f1f3fa55e998cd6021af7614275c3a1afb8b501.tar.bz2
54-5f1f3fa55e998cd6021af7614275c3a1afb8b501.zip
feat: set exif orientation data on stored jpegs
-rw-r--r--lib/exif_wrapper.cpp5
-rw-r--r--main.scm55
-rw-r--r--makefile14
3 files changed, 41 insertions, 33 deletions
diff --git a/lib/exif_wrapper.cpp b/lib/exif_wrapper.cpp
index e6b60b1..eab5598 100644
--- a/lib/exif_wrapper.cpp
+++ b/lib/exif_wrapper.cpp
@@ -36,11 +36,6 @@ extern "C" unsigned int getExifOrientation(uint8_t* imgBytes, unsigned int size)
}
extern "C" void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigned int orientation) {
- int chk = 0;
- for (int i = 0; i < size; i++) {
- chk = (chk + (int)imgBytes[i] * 13) % 100000;
- }
- printf("start chk:%d\n",chk);
try {
// Hack to work around Exiv2 seeming to refuse to write back to blob, but will write
// back to a file. Create temp file -> operate on it -> copy back to blob, unlink file.
diff --git a/main.scm b/main.scm
index acb9363..2dce9b0 100644
--- a/main.scm
+++ b/main.scm
@@ -1,5 +1,5 @@
(import
- scheme (chicken base)
+ scheme (chicken base) (chicken foreign)
(chicken format) (chicken port) (chicken io) (chicken random) (chicken time)
(chicken process-context) (chicken irregex) (chicken condition) (chicken blob)
spiffy intarweb uri-common html-parser spiffy-request-vars multipart-form-data
@@ -138,9 +138,18 @@
(define (children-count p) (sixth p))
(define (has-image? p) (= 1 (seventh p)))
+(foreign-declare "#include \"exif_wrapper.h\"")
+(define (get-exif-orientation raw-img-vec)
+ ((foreign-lambda unsigned-int "getExifOrientation" u8vector unsigned-int)
+ raw-img-vec
+ (u8vector-length raw-img-vec)))
-
+(define (set-exif-orientation! raw-img orientation)
+ ((foreign-lambda void "setExifOrientation" blob unsigned-int unsigned-int)
+ raw-img
+ (blob-size raw-img)
+ orientation))
(define dim-max 512)
@@ -161,29 +170,24 @@
))))
(define (img->jpeg-blob img)
-
-(with-output-to-file "/tmp/raw.jpg" (lambda () (display (blob->string (u8vector->blob img)))))
-
-
- (let*-values ([(raw width height channels) (load-image img)]
- [(target-width target-height) (target-dimensions width height)])
-(with-output-to-file "/tmp/test2.png"
- (lambda ()
- (write-png
- raw
- width
- height
- channels)
- ))
- (string->blob
- (with-output-to-string
- (lambda ()
- (write-jpg
- (image-resize raw width height channels target-width target-height)
- target-width
- target-height
- channels)
- )))))
+ (and img
+ (let*-values
+ ([(orientation) (get-exif-orientation img)]
+ [(raw width height channels) (load-image img)]
+ [(target-width target-height) (target-dimensions width height)]
+ [(resized-jpg)
+ (string->blob
+ (with-output-to-string
+ (lambda ()
+ (write-jpg
+ (image-resize raw width height channels target-width target-height)
+ target-width
+ target-height
+ channels)
+ )))])
+ (set-exif-orientation! resized-jpg orientation)
+ resized-jpg
+ )))
(define users (alist->hash-table '(("lawrence" . "pw") ("demo" . "pw") ("dan" . "pw"))))
@@ -238,7 +242,6 @@
[target "_blank"]
[rel "noreferrer"])
,x)) (irregex-extract r content))])
- (display `(,texts ,links))
(define (go xs ys take-y?)
(cond
[(and (not (null-list? ys)) take-y?)
diff --git a/makefile b/makefile
index afb604d..a0c161f 100644
--- a/makefile
+++ b/makefile
@@ -1,7 +1,17 @@
-build: ./main.scm
+build: ./main.scm build-cpp
mkdir -p ./build
- chicken-csc -static ./main.scm -L -lsqlite3
+ chicken-csc -static ./main.scm \
+ -L -lsqlite3 \
+ -L lib/exif_wrapper.o \
+ -L /lib/libexiv2.so \
+ -L /usr/lib/libstdc++.so.6 \
+ -C -Ilib/
mv ./main ./build/main
+build-cpp:
+ g++ -g -c lib/exif_wrapper.cpp -o lib/exif_wrapper.o
+run: build
+ ./build/main
+
deploy: build
cp ./style.css ./build/style.css
cp ./favicon_io/favicon.ico ./build/favicon.ico