Skip to content
Browse files

wrangle stuff to make dthr filtrs work; omgwtf http timeout???

  • Loading branch information...
1 parent 6bbb233 commit c1787e0a3bcce533f7a1db92136d7116214d1973 straup committed Jul 22, 2012
Showing with 86 additions and 7 deletions.
  1. +3 −1 bin/upload_by_email.php
  2. +10 −5 filtr/filtr
  3. +66 −0 filtr/utils/dither.py
  4. +7 −1 www/include/lib_flickr_photos_upload.php
View
4 bin/upload_by_email.php
@@ -130,7 +130,9 @@
foreach ($uploads as $path){
- $args = array();
+ $args = array(
+ 'http_timeout' => 60
+ );
if (($filtr) && features_is_enabled("uploads_filtr")){
$args['filtr'] = $filtr;
View
15 filtr/filtr
@@ -15,7 +15,7 @@ VERSION="0.5"
case $1 in
''|-h|-help|--help|-u|--usage|'-?')
echo "${NAME} ${VERSION}"
- echo "Usage: `basename $0` in.jpg out.jpg [filtr|dazd|postr|postcrd|rockstr|pxl]"
+ echo "Usage: `basename $0` in.jpg out.jpg [filtr|dazd|postr|postcrd|rockstr|pxl|dthr]"
echo " `basename $0` in.mp4 out.jpg movr <filter>"
echo " `basename $0` in1.jpg in2.jpg heathr <in1-filtr> <in2-filtr> out.jpg"
echo " `basename $0` in1.jpg in2.jpg stndpipe <in1-filtr> <in2-filtr> out.jpg"
@@ -175,7 +175,7 @@ fi
# which filtr is being run?
case $FILTER in
- dazd|movr|postr|postcrd|pxl|rockstr|stndpipe|tilt)
+ dazd|dthr|movr|postr|postcrd|pxl|rockstr|stndpipe|tilt)
;;
heathr)
FILTER="stndpipe"
@@ -201,9 +201,7 @@ echo "[startup] input UID is ${FILTR_UID}"
# tmp/work files
-# FIX ME: check OS...
-# TMP=`mktemp -d -t ${FILTR_UID}`
-TMP=`mktemp -d`
+TMP=`mktemp -d -t ${FILTR_UID}`
ID="${TMP}/${FILTR_UID}-${FILTER}-id.txt"
LOMO="${TMP}/${FILTR_UID}-${FILTER}-lomo.png"
@@ -321,6 +319,13 @@ case $FILTER in
;;
+ dthr)
+
+ echo "[${FILTER}] dither"
+ ${PYTHON} ${UTILS}/dither.py ${INPUT} ${OUTPUT}
+
+ ;;
+
rockstr)
echo "[${FILTER}] create output"
View
66 filtr/utils/dither.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+has_atk = False
+
+import sys
+
+try:
+ import atk
+ has_atk = True
+except Exception, e:
+ pass
+
+try:
+ import Image
+except Exception, e:
+ import PIL.Image as Image
+
+
+def dither(infile, outfile):
+
+ img = Image.open(infile)
+
+ if has_atk:
+ img = dither_atk(img)
+ else:
+ img = dither_python(img)
+
+ img.save(outfile)
+
+def dither_atk(img):
+
+ img = img.convert('L')
+ tmp = atk.atk(img.size[0], img.size[1], img.tostring())
+ new = Image.fromstring('L', img.size, tmp)
+
+ return new.convert('RGBA')
+
+def dither_python(infile, outfile):
+
+ img = img.convert('L')
+
+ threshold = 128*[0] + 128*[255]
+
+ for y in range(img.size[1]):
+ for x in range(img.size[0]):
+
+ old = img.getpixel((x, y))
+ new = threshold[old]
+ err = (old - new) >> 3 # divide by 8
+
+ img.putpixel((x, y), new)
+
+ for nxy in [(x+1, y), (x+2, y), (x-1, y+1), (x, y+1), (x+1, y+1), (x, y+2)]:
+ try:
+ img.putpixel(nxy, img.getpixel(nxy) + err)
+ except IndexError:
+ pass
+
+ return img.convert('RGBA')
+
+if __name__ == '__main__':
+
+ infile = sys.argv[1]
+ outfile = sys.argv[2]
+
+ dither(infile, outfile)
View
8 www/include/lib_flickr_photos_upload.php
@@ -53,8 +53,14 @@ function flickr_photos_upload(&$user, $file, $args=array()){
}
+ $more = array();
+
+ if (isset($args['http_timeout'])){
+ $more['http_timeout'] = $args['http_timeout'];
+ }
+
# default upload perms?
- $rsp = flickr_api_upload($file, $args);
+ $rsp = flickr_api_upload($file, $args, $more);
$rsp['do_archive'] = $GLOBALS['cfg']['enable_feature_uploads_archive'];
$rsp['archived_ok'] = 0;

0 comments on commit c1787e0

Please sign in to comment.
Something went wrong with that request. Please try again.