Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I frequently order prints online. However the printing-service is automated and crops out the pictures I upload to a 4x5 ratio. I'd like to be able to add margins (e.g. white) to the pictures BEFORE I upload them, so that they are in 4x5 aspect ratio.

I need to do this for several pictures, so is there a script / macro I can use? You may suggest a solution based on Photoshop.

share|improve this question
    
What image file format(s) are involved? –  martineau Jan 28 '11 at 15:16

3 Answers 3

Photoshop can be scripted using what it calls Actions. They're a lot like macros and can be recorded, edited, and played all within the program. Once you've created one, it can be executed manually on individual images or applied to all the images in a folder.

There's extensive information about them in Photoshop's Help. There's also a great number of free ones on the web for all kinds of tasks, so it wouldn't surprise me if there was one that does what you want...or close to it. If not, what you'd like to do sounds fairly easy, so it probably wouldn't be that hard to create your own (assuming you know how to go about doing it in the program). Alternatively, you could download a free one that's close or similar to your goal and edit (modify) it.

Update: I found this web tutorial on creating your own actions -- How to: Crop 10 or more images to a defined size using actions and batch processing in Adobe Photoshop.

share|improve this answer
    
To expand on this a little: since the end result is physical prints, one option is to take all of the landscape (aka horizontal) photos, rotate them 90 degrees, and then save as a temporary copy. This way all the photos you are sending to the service are in one orientation. If your photos are not 4x5 (or 8x10) to begin with, you can then take all the photos and apply one tranformation to them all to have them all 5 inches wide. Then the auto-crop won't crop them. Once you figure out your workflow, the actions can be automated as martineau suggested. –  horatio Jan 28 '11 at 16:06

You can do this using a command-line tool that's part of ImageMagick. It's available for Unix/Linux, OS X and Windows.

For example:

convert *.jpg -bordercolor white -border +10+10 %t-4x5.%e

Adds a 10-pixel border around the image. To do aspect-ratio padding, things have to be quite a bit more complex. Here is a Bash script that uses ImageMagick to do what you want: aspectpad.

share|improve this answer

I wrote a script in Matlab that solves the problem: It reads all the images in the directory and adds a black margin to achieve the desired aspect ratio.

% Margins

% SPECIFY RATIO
RATIO_HEIGHT = 10;
RATIO_WIDTH = 8;

% READ FILES
files = dir('*.jpg');

% START
clc
for f=1:size(files)
    % READ FILE
    IMG = imread(files(f).name);
    [h w d] = size(IMG);

    % CALCULATE RATIO
    ratio = w/h;

    % PRINT FILENAME
    fprintf('\n\n-------------------------------------');
    fprintf('\n# PROCESSING FILE: \t%s', files(f).name);

    % PRINT ORIENTATION
    if(h > w)
        orientation = 1;
        fprintf('\nPORTRAIT');
    else
        orientation = 2;
        fprintf('\nLANDSCAPE');
    end

    % PRINT DIMENSIONS
    fprintf('\t|\t%i x %i', h, w);

    % CHECK RATIO?
    if(h/w == RATIO_HEIGHT/RATIO_WIDTH)
        fprintf('\n > Correct aspect ratio.');
        NIMG = IMG;        
    else
        fprintf('\n! BAD aspect ratio : %f', h/w);

        % CALCULATE NEW DIMENSIONS
        if(ratio < RATIO_WIDTH/RATIO_HEIGHT)
            ch = h;
            cw = round(RATIO_WIDTH/RATIO_HEIGHT*ch);
        else
            cw = w;
            ch = round(RATIO_HEIGHT/RATIO_WIDTH*cw);
        end

        % PRINT NEW DIMENSIONS
        fprintf('\nNEW DIMENSIONS: \t%i x %i | ADDED: %i x %i', ch, cw, ch-h, cw-w);

        % CREATE NEW IMAGE
        NIMG = uint8(zeros(ch,cw,d));

        % COPY
        for k=1:d
            for i=1:h
                for j=1:w
                    NIMG(i,j,k) = IMG(i,j,k);
                end
            end
        end
    end

    % WRITE
    imwrite(NIMG, ['modified\' files(f).name '.png'], 'png');
end
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.