#!/usr/bin/perl # -------------------------------------------------------------------- # PHOTO PRINT VERSION 0.2.1 # -------------------------------------------------------------------- # Photoprint prepares images for printing them to photopaper. It # rotates them and cuts the sides off, so that they match the # direction and the propotions of the photopaper. Afterwards it # executes a printing command. use Image::Magick; use File::Basename; # -------------------------------------------------------------------- # SETTINGS # -------------------------------------------------------------------- # Width and height of the photopaper. Unit doesn't matter, take care that # the paper size is selected currectly in $PrintCmd. Here only the # proportions are interesting. my $PaperWidth= 5; my $PaperHeight= 7; # Where to save the modified pictures temporary? my $TmpPath= "/tmp/"; # Command to print a jpeg file. This is a command for the Canon PIXMAX # iP4200 with TurboPrint (www.turboprint.info). If you use gtklp, try # this: "gtklp -l". ATTENTION: Please take care that this command # will scale them image to fit the paper (e.g. "-o scaling=100 # position=center"). my $PrintCmd= "/usr/bin/lp -o Resolution=600x600dpi_3 -o zedoMirror=0 -o zedoDuplexAdjust=0 -o zedoDithering=ErrorDiffusion -o zedoColorModel=RGB -o zedoPrinterDriver=Canon-PIXMA-iP4200 -o zedoLicenseCount=1 -o zedoLicensedTo=LicenseOwner -o zedoLicenseType=Private -o zedoUserColor=0 -o zedoColorCorrection=1 -o zedoColorY=0 -o zedoColorM=0 -o zedoColorC=0 -o zedoColorK=0 -o zedoGamma=180 -o zedoGamut=0 -o zedoIntensity=0 -o zedoContrast=5 -o zedoBrightness=-15 -o PageSize=5x7inBorderless -o MediaType=CanonPhotoPaperProPR101_4 -o InputSlot=LowerTray -o Duplex=None -o fitplot=true -o scaling=100 -o position=center -o wrap=false -o number-up-layout=btlr -o number-up=1 -o outputorder=normal -o copies=1"; # -------------------------------------------------------------------- die "Please specify a jpeg-file!\n" unless $ARGV[0]; my $photo= Image::Magick->new(); # Read image my $filename= $ARGV[0]; $photo->Read($filename); my ($width, $height)= $photo->Get('width', 'height'); # Rotate image if ($width > $height) { $photo->Rotate(degrees => '90'); ($width, $height)= $photo->Get('width', 'height'); }; my $f= $height/$width; my $pf= $PaperHeight/$PaperWidth; if ($f < $pf) { # cut the sides off -- left and right my $nwidth= $height/$pf; $photo->Crop(width => $nwidth, height => $height, x => ($width- $nwidth)/2, y => 0); }; if ($f > $pf) { # cut the sides off -- top and bottom my $nheight= $width * $pf; $photo->Crop(width => $width, height => $nheight, x => 0, y => ($height- $nheight)/2); } ($width, $height)= $photo->Get('width', 'height'); # Print... my $tmpname= $TmpPath.basename($filename); $photo->Write($tmpname); system($PrintCmd.' '.$tmpname); unlink ($tmpname); exit;