DIT-fanzine

From XPUB & Lens-Based wiki
Revision as of 20:31, 23 September 2010 by Migratebot (talk | contribs) (Created page with " == DIT-fanzine == make pdfs (you need to install cups-pdf for that pdfs go in the directory ~/PDF/ <source lang="text"> # sudo apt-get install cups-pdf lpr code.py -P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

DIT-fanzine

make pdfs (you need to install cups-pdf for that pdfs go in the directory ~/PDF/

# sudo apt-get install cups-pdf

lpr code.py -P PDF
mv ~/PDF/code.pdf .

lpr bami.png -P PDF
cp ~/PDF/bami.pdf
.


resize JPGs (in this case all of them) to 320*240px

mogrify -resize 320x240 *.JPG



takes image from two folders and performs the dissolve function on them


xRANGE=480
yRANGE=640

#rename all images in folder image01 to one0001.jpg one0002.jpg... and copy them into the folder where the script is
cd images01
convert * one%04d.jpg
cp one* ..
cd ..
#rename all images in folder image02 to two0001.jpg two0002.jpg... and copy them into the folder where the script is
cd images02
convert * two%04d.jpg
cp two* ..
cd ..

#this is a loop that now does ten times the same thing, namely:
for ((i=0;i<10;i+=1))
do
#picking a random file that starts with one
set -- one*
length=$#
random_one=$(( $RANDOM % ($length + 1) ))
#echo ${!random_one}
one=${!random_one}

#and a random file that starts with two
set -- two*
length=$#
random_two=$(( $RANDOM % ($length + 1) ))
#echo ${!random_two}
two=${!random_two}

#and then dissolves the two random files over each other and names it 0.jpg 1.jpg.. 9.jpg which makes 10 new jpges in total, hooray
filename=$i.jpg
convert -size $((xRANGE))x$((yRANGE)) xc:white $filename
composite -dissolve 50  -gravity South \
           $one $two \
$filename

done



take images from a folder called image and place them randomly on a white canvas and write "happy happy joy joy"

xRANGE=480
yRANGE=640

cd image
#we rename the images because numbers in the image over function do not work
rename 'y/0-9/a-z/' *
convert -size $((xRANGE))x$((yRANGE)) xc:white image.gif



for i in $(ls)
do
x=$RANDOM 
let "x %= $xRANGE"
x=$((x-100))
y=$RANDOM
let "y %= $yRANGE"
y=$((y-100))
convert image.gif -draw "image over $x,$y 150,122 $i" image.gif

done


convert -font BradleyGratis.ttf -fill yellow -pointsize 35 \
-draw 'text 10,400 "happy happy joy joy"' \
image.gif output.jpg 

cp output.jpg ..
rm output.jpg
rm image.gif
cd ..
display output.jpg



for i in $(ls)
do
composite -dissolve 50 $i loading.gif composed$i
done

#takes all files from the directory and composes it 50% over an image called loading.gif



spider.py Custom image download from any website:

import urllib2, urlparse, os, sys
import html5lib
 
def absolutizeURL (href, base):
    if not href.lower().startswith("http://"):
        return urlparse.urljoin(base, href)
    return href

def openURL (url, data):
    """
    returns (page, actualurl)
    sets user_agent and resolves possible redirection
    realurl maybe different than url in the case of a redirect
    """    
    request = urllib2.Request(url)
    user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.5) Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5"
    request.add_header("User-Agent", user_agent)
    pagefile=urllib2.urlopen(request, data)
    realurl = pagefile.geturl()
    return (pagefile, realurl)

def downloadURL (url, foldername=""):
    """
    returns (page, actualurl)
    sets user_agent and resolves possible redirection
    realurl maybe different than url in the case of a redirect
    """    
    request = urllib2.Request(url)
    user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080418 Ubuntu/7.10 (gutsy) Firefox/2.0.0.14"
    request.add_header("User-Agent", user_agent)
    pagefile=urllib2.urlopen(request)
    realurl = pagefile.geturl()

    # make a filename based on the URL, inside foldername (if given)
    urlpath = urlparse.urlparse(url)[2]
    (path, filename) = os.path.split(urlpath)
    filename = os.path.join(foldername, filename)
    out = open(filename, "wb")
    bytes = 0
    while True:
        data = pagefile.read(1024)
        if not data: break
        bytes += len(data)
        out.write(data)
    out.write(data)
    pagefile.close()
    out.close()
    return bytes


def spiderImages (url, postdata=None, foldername=""):
    """
    Opens an HTML page at a URL, and downloads all the images (those referenced in <img> tags, images from css are not!)
    Files are put inside foldername if given.
    """
    if foldername and not os.path.isdir(foldername):
        os.mkdir(foldername)
    f, url2 = openURL(url, postdata)
    parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))
    tree = parser.parse(f)
    f.close()
    tree.normalize()
    count = 0; totalbytes = 0
    for node in tree.getElementsByTagName("img"):
        src = node.getAttribute("src")
        if src:
            src = absolutizeURL(src, url2)
            print >> sys.stderr, src
            bytes = downloadURL(src, foldername)
            if bytes:
                totalbytes += bytes
                count += 1
    return count, totalbytes

if __name__ == "__main__":
    spiderImages("http://cnn.com", None, "test")



Polaroid+shadow-effect all images in the folder:

montage -polaroid -10 -shadow *.jpg new.jpg


Jakubs script for 256 circles:

str=""
xRANGE=480
yRANGE=640

color=0	

for ((i=0;i<256;i+=1))
do
x=$RANDOM
let "x %= $xRANGE"
y=$RANDOM
let "y %= $yRANGE"
draw="fill rgb($color, $color, $color) circle $x,$y $((x+10)),$((y+10)) "
str="$str$draw"
color=$((color+1))
done

convert -size 480x649 xc:black  \
        -draw "$str" neww.jpg

display neww.jpg


Attachments