Primitive

Primitive

what is needed to get started?

Primitive is a cli program that takes your input image(s) make cool looking art with them using basic shapes, find the github page here, primitive does not come with a binary executable by default, you can either install golang and compile it yourself or download the binary version of windows or linux from my repo here

source material

everything is downloaded from a royalty free image website here

explanation of the switches and how the program works

Flag Default Description
i n/a input file
o n/a output file
n n/a number of shapes
m 1 mode: 0=combo, 1=triangle, 2=rect, 3=ellipse, 4=circle, 5=rotatedrect, 6=beziers, 7=rotatedellipse, 8=polygon
rep 0 add N extra shapes each iteration with reduced search (mostly good for beziers)
nth 1 save every Nth frame (only when %d is in output path)
r 256 resize large input images to this size before processing
s 1024 output image size
a 128 color alpha (use 0 to let the algorithm choose alpha for each shape)
bg avg starting background color (hex)
j 0 number of parallel workers (default uses all cores)
v off verbose output
vv off very verbose output

combo examples

primitive -i cheetah.jpg -o c_0.jpg -n 1000 -m 0 -s 1280 -v

c_0

primitive -i lion.jpg -o l_0.jpg -n 500 -m 0 -s 1280 -v

l_0

primitive -i cow.jpg -o c2_0.jpg -n 250 -m 0 -s 1280 -v

c2_0

triangle examples

primitive -i monkey.jpg -o m_1.jpg -n 500 -m 1 -s 1280 -v

m_1

primitive -i flamingo.jpg -o f_1.jpg -n 750 -m 1 -s 1280 -v

f_1

primitive -i flamingo.jpg -o f_1.jpg -n 750 -m 1 -s 1280 -v

s_1

rectangle examples

primitive -i zebra.jpg -o z_2.jpg -n 500 -m 2 -s 1280 -v

z_1

primitive -i ostrich.jpg -o o_2.jpg -n 250 -m 2 -s 1280 -v

o_2

primitive -i camel.jpg -o c_2.jpg -n 1000 -m 2 -s 1280 -v

c_2

ellipses examples

primitive -i panda.jpg -o p_3.jpg -n 750 -m 3 -s 1280 -v

p_3

primitive -i elephant.jpg -o e_3.jpg -n 500 -m 3 -s 1280 -v

e_3

primitive -i chicken.jpg -o c_3.jpg -n 1000 -m 3 -s 1280 -v

c_3

circle examples

primitive -i bunny.jpg -o b_4.jpg -n 1000 -m 4 -s 1280 -v

b_4

primitive -i crab.jpg -o c_4.jpg -n 250 -m 4 -s 1280 -v

c_4

primitive -i dog.jpg -o d_4.jpg -n 500 -m 4 -s 1280 -v

d_4

rotated rectangle examples

primitive -i shark.jpg -o s_5.jpg -n 250 -m 5 -s 1280 -v

s_5

primitive -i horse.jpg -o h_5.jpg -n 500 -m 5 -s 1280 -v

h_5

primitive -i penguin.jpg -o p_5.jpg -n 750 -m 5 -s 1280 -v

p_5

beziers examples

for beziers we also use the -rep 10 switch which multiplies the number of shapes by 10 for each iteration its adding, this is because lines are harder to make out if not many of them are present

primitive -i fox.jpg -o f_6.jpg -n 500 -m 6 -s 1280 -rep 10 -v

f_6

primitive -i wolf.jpg -o w_6.jpg -n 250 -m 6 -s 1280 -rep 10 -v

w_6

primitive -i cat.jpg -o c_6.jpg -n 750 -m 6 -s 1280 -rep 10 -v

c_6

rotated ellipses examples

primitive -i hamster.jpg -o h_7.jpg -n 500 -m 7 -s 1280 -v

h_7

primitive -i fish.jpg -o f_7.jpg -n 250 -m 7 -s 1280 -v

f_7

primitive -i fish.jpg -o f_7.jpg -n 250 -m 7 -s 1280 -v

g_7

polygon examples

primitive -i butterfly.jpg -o b_8.jpg -n 250 -m 8 -s 1280 -v

b_8

primitive -i hawk.jpg -o h_8.jpg -n 100 -m 8 -s 1280 -v

h_8

primitive -i deer.jpg -o d_8.jpg -n 500 -m 8 -s 1280 -v

d_8

fun with gifs

each time you convert an image with primitive the output is different even with the same setting switches, this makes creating animated gifs very easy, just duplicate your image a few times, convert them with primitive

for i in *.jpg ; do echo $i ; primitive -i $i -o p-$i -n 500 -m 0 -v ; done

and then mux them together

cat p-bird*.jpg | ffmpeg -framerate 5 -f image2pipe -i - bird.gif

bird

iterate over an image with the same settings multiple times

lets convert this image 10 times with the same settings in one command

for t in {1..10} ; do echo $t ; primitive -i koala.jpg -o k-$t.jpg -n 500 -m 1 -v ; done

and mux the images

cat k-* | ffmpeg -framerate 10 -f image2pipe -i - koala.gif

koala

iterate over an image with progressing shape numbers

lets convert this image 100 times with every image having 1 shape count more than the last one, starting at 1 shapes count and ending on 100

for t in {1..100} ; do echo $t ; primitive -i spider.jpg -o s-$t.jpg -n $t -m 0 -v ; done

and mux the images

cat s-* | ffmpeg -framerate 15 -f image2pipe -i - spider.mp4

the outpot gif was quite large so i decided to add this as a mp4 video, you can have the video looped forever by right clicking on it and tick on loop

iterate over an image with progressing shape numbers X 5

lets convert this image 100 times, starting with 1 shape and then 6 and 11 and 16 etc to get to 500 shapes in the 100th picture …

for t in {001..500..5} ; do echo $t ; primitive -i buffalo.jpg -o b-$t.jpg -n $t -m 5 -v ; done

and mux the images

cat b-* | ffmpeg -framerate 15 -f image2pipe -i - buffalo.mp4

primitify a video

lets apply what we learned to a video, i have made a example of how to download a free video, make image sequence, apply filter and mux it back here

for i in image-000*.jpg ; do echo $i ; primitive -i $i -o p-$i.jpg -n 250 -m 0 -s 1280 -v ; done

and mux the images

cat p-image-000*.jpg | ffmpeg -framerate 30 -f image2pipe -i - fish+.mp4

windows bat file and linux bash script

there is also my repo with easy to use bat and scripts to make life easier for batch proccessing