Deviant Art Shop Forum More Submit Join Login

# Bash, Pythagoras, and ImageMagickby fantasyui-com

UPDATE: I made an Open Source (MIT) version with more artwork, you can download it here: github.com/fantasyui-com/mocku… totally free! It is a great program, it is meant to be completely automatic, just pick some photos, pick some profiles, and when it finishes pick the best results.

This is based on Alejandro Escamilla's photo unsplash.com/@alejandroescamil… I am using simple ImageMagick commands, to combine it together. I made no attempts at not using a transparent foreground layer, I just assume something will obscure the centerpiece, for this reason the script below depends on a png with a hole where the screen is. This only seems sub optimal, by placing Alejandro image over everything the feathered corners blend perfectly, there is no question about perfecting geometry of the underlying layers, everything just works.

Here is the final bash script:

#!/bin/bash
# source image: unsplash.com/photos/xII7efH1G6…

IW=5616
IH=3744

#
#  A       C
#
#
#  B       D
#

AX=1724
AY=541

BX=1814
BY=1736

CX=3855
CY=539

DX=3783
DY=1742

# create a blank canvas
convert -size \${IW}x\${IH}^ canvas:transparent layer-01.png;

# get the width and then height of the hole (based on the four hole coordinates)
HW=\$(echo "scale=2;sqrt(((\${CX}-\${AX})^2)+((\${CY}-\${AY})^2))"|bc)
HH=\$(echo "scale=2;sqrt(((\${BX}-\${AX})^2)+((\${BY}-\${AY})^2))"|bc)

# resize input image to match the artwork hole.
convert input.png -resize \${HW}x\${HH}^ -crop \${HW}x\${HH}+0+0 -sharpen 0x2 -quality 100 input-to-size.png;

# insert resized input image into blank canvas;
composite -geometry +0+0 input-to-size.png layer-01.png layer-01.png;

# four point distort of the input image recently placed on blank canvas, to fit into the upcoming artwork hole
convert layer-01.png -matte -virtual-pixel transparent -distort Perspective "0,0,\${AX},\${AY} 0,\${HH},\${BX},\${BY} \${HW},0,\${CX},\${CY} \${HW},\${HH},\${DX},\${DY}" layer-01.png;

# place artwork layer over the resized/distorted input image and save result
composite -geometry +0+0 layer-02.png layer-01.png result.png;

Submitted on
October 20, 2016
Image Size
1.7 MB
Resolution
1280×800