From 889c58413b613d234e880007966fc38b262d77e2 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 13 Mar 2023 16:30:13 -0400 Subject: partial-fix: images not corrupted (but still not displaying with correct orientation) --- main.scm | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'main.scm') diff --git a/main.scm b/main.scm index 2dce9b0..42bc2b4 100644 --- a/main.scm +++ b/main.scm @@ -1,5 +1,5 @@ (import - scheme (chicken base) (chicken foreign) + scheme (chicken base) (chicken foreign) (chicken file posix) (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 @@ -145,11 +145,18 @@ 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 (set-exif-orientation raw-img orientation) + (let-values + ([(fd file-path) (file-mkstemp "/tmp/image-temp.XXXXXX")]) + (file-write fd raw-img) + (file-close fd) + ((foreign-lambda void "setExifOrientation" nonnull-c-string unsigned-int) + file-path + orientation) + (let + ([port (open-input-file file-path #:binary)]) + (u8vector->blob/shared (read-u8vector #f port))) + )) (define dim-max 512) @@ -185,11 +192,9 @@ target-height channels) )))]) - (set-exif-orientation! resized-jpg orientation) - resized-jpg + (set-exif-orientation resized-jpg orientation) ))) - (define users (alist->hash-table '(("lawrence" . "pw") ("demo" . "pw") ("dan" . "pw")))) (define apikeys (make-hash-table)) -- cgit v1.2.3