K
K
kostrukov2012-03-03 20:49:09
Macros
kostrukov, 2012-03-03 20:49:09

Streaming sub-image replacement

Tell me how to organize the process of replacing a certain (hard-coded coordinates) fragment on a series of photos. Let me explain, there is a program that generates ready-made state documents from the input data. Some time ago, the document standard changed, and the programmer-creator (along with the source code) is not possible to find. You just need to take one line and replace it with another of a new type, but on several tens or hundreds of documents.

I know that this is a very ordinary task for a programmer, but maybe there is a simpler way like a macro for Photoshop or ready-made software?

%username%, help!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
avalak, 2012-03-03
@avalak

A simple option for win: take IrfanView and batch add a watermark patch according to this instruction to those files that already exist.
Simple version for *nix:

#!/usr/bin/env bash
#

# фиксим пробелы в именах файлов
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

#новый фрагмент
REPL="../base.png"

# переходим в каталог с исходными файлами "in"
cd in
for file in *.jpg
do
    echo "Processing $file file..";
    # наложить фрагмент на исходное изображение 110px слева 110px сверху 
    # и сохранить результат в каталог ../out под тем же именем
    convert ${file} ${REPL} -geometry +110+110 -composite ../out/${file}
done
IFS=$SAVEIFS


With those that will appear in the process of work, it is a little more difficult. For *nix, I would write an inotify + imagemagick shell script to monitor and process files in a directory. But this will not work in win, because there is neither shell nor inotify.
Alternative: .NET FileSystemWatcher. Perhaps someone will write a watchman (I do not use .NET). Otherwise, you will either have to pull the script, or use IrfanView

A
Akson87, 2012-03-03
@Akson87

I can offer a bunch of Python + OpenCV, a small script in a couple of dozen lines should solve the problem.

N
newpavlov, 2012-03-03
@newpavlov

Here is a Python function for inserting an image into another (requires the Python Imaging Library): main and mark are the paths to the main image (document) and the one being inserted (fragment), respectively. coor is a pair of (x, y) coordinates for the insertion point, and output is the path for the output file. Usage example: Write a body kit to bypass all the necessary files, I think it will not be difficult.
from PIL import Image
def paste_mark(main, mark, coor, output):
img = Image.open(main)
mrk = Image.open(mark)
img.paste(mrk, coor)
img.save(output)

paste_mark('document.jpg', 'fragment.jpg', (100, 200), 'output.jpg')

M
maxgalkin, 2012-03-04
@maxgalkin

If you have Photoshop, then very quickly you can record a sequence of actions using one of your document photos as an example. Moreover, it is simple that the row insertion coordinates are fixed.
Windows / Actions
And further, apply the recorded script to the entire batch of documents (to the folder with photos)
File / Automate / Batch ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question