Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux create Image pixel by pixel in command line

Is there a way in Linux to create an image and construct it pixel by pixel directly in command line?

I tried imagemagick, but its only possible to create a blank image without set pixels seperate.

Any Idea?

like image 396
Denis Avatar asked Oct 04 '16 20:10

Denis


2 Answers

Ok, so we start with a red pixel:

convert xc:red image.png

I'll enlarge it - it is rather small.

enter image description here

Now we get a blue one and want to add it:

convert image.png xc:blue +append image.png

enter image description here

Then someone gives us an RGB pixel:

convert image.png xc:"rgb(255,255,0)" +append image.png

enter image description here

Now some trouble-maker comes along with an HSL pixel:

convert image.png xc:"hsl(120,100,100)" +append image.png

enter image description here

Be careful not to use JPEG though as it is lossy.

like image 72
Mark Setchell Avatar answered Oct 15 '22 12:10

Mark Setchell


You can use shell scripting to build a ppm image.

echo "P2"
echo "# Column (width) Row (height)"
echo "$1 $1\n1"

t=`expr $1 / 8`
for i in `seq 1 4`; do
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "1 "; done
            for i in `seq 1 $t`; do echo -n "0 "; done
        done
        echo
    done
    for i in `seq 1 $t`; do
        for i in `seq 1 4`; do
            for i in `seq 1 $t`; do echo -n "0 "; done
            for i in `seq 1 $t`; do echo -n "1 "; done
        done
        echo
    done
done

To run the above code do:

$ sh filename.sh 120 > im1.ppm ; eog im1.ppm

The result is: enter image description here

like image 30
Josue Villegas Avatar answered Oct 15 '22 12:10

Josue Villegas