PHPBuilder - Command Line Picture Merge

RSS Twitter

Command Line Picture Merge

by: William Berggren
September 17, 2002

Version: 1.0

Type: Full Script

Category: Graphics

License: zlib/libpng License

Description: This will combine 2 pictures. 50% on left and 50% on right. It will also scale down to 400x300 for ebay and put a border around it. This script runs on command line if imagemagick and php standalone are installed.

#!/usr/local/bin/php -q
 Written by William L. Berggren
 Public Domain - Free
// wow you don't even need print statements.
// shaabang line, -q suppresses html headers 
print ("The purpose of this program is to merge 2 640x480.\n");
print ("pictures - or similar ratio - into a 400x300 picture\n");
print ("This is for ebay. Initally this will only be done by\n");
print ("cropping in the x-axis (Left-Right).  You must edit the\n"); 
print ("default directory.  This will be the path to a.jpg and b.jpg\n");
print ("Imagine a scale from 0-100 that starts at 0 on the\n");
print ("left side of the picture, and 100 in the middle.  Entering 50\n");
print ("will crop 25% off the left side and 25% from the right side\n");
print ("of the picture. Picture names will always be a.jpg for \n");
print ("the left picture, and b.jpg for the right picture.\n");
print ("c.jpg will be the combined picture \n");
print ("DEPENDICIES, are imagemagick and php standalone\n");
print ("this is easy to test enter convert, mogrify, and php \n");
print ("at the command line and something should happen. \n \n");

//default directory, EDIT THE FOLLOWING LINE
print ("The present directory is named: $d\n");

print (" Picture a.jpg offset, 0-100: ");
$fp = fopen("php://stdin", "r");
$a = fgets($fp,255);
print (" Picture b.jpg offset, 0-100: ");
$b = fgets($fp,255);

// resizes pictures a,b to 640x480
exec("mogrify -scale 640x480 -quality 95  " . $d . "/a.jpg");
exec("mogrify -scale 640x480 -quality 95  " . $d . "/b.jpg");

$aa = "convert -quality 90 -crop 320x480+";
$ab = " " . $d . "/a.jpg";
$bb = " " . $d . "/b.jpg";
$ac = " " . $d . "/aa.jpg";
$cc = " " . $d . "/bb.jpg";

// crops picture a.jpg and saves it as aa.jpg
$yy = $aa . $a . $ab . $ac;
print ("$yy\n");

// crops picture b.jpg and saves it as bb.jpg
$zz = $aa . $b . $bb . $cc;
print ("$zz\n");

// joins the 2 pictures, as picture c.jpg.
$adjoin = "convert -quality 80 +append ";
$adjoin .= $d . "/aa.jpg ";
$adjoin .= $d . "/bb.jpg ";
$adjoin .= $d . "/c.jpg";
print ("$adjoin\n");

// resizes picture c.jpg to 400x300 and adds border.
$edge="mogrify -scale 400x300 -quality 75 -raise 4x4 -sharpen 1x1 " . $d . "/c.jpg"; 
print ("$edge\n");


Comment and Contribute

Your comment has been submitted and is pending approval.

William Berggren



(Maximum characters: 1200). You have characters left.