Answer the question
In order to leave comments, you need to log in
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
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
I can offer a bunch of Python + OpenCV, a small script in a couple of dozen lines should solve the problem.
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')
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 questionAsk a Question
731 491 924 answers to any question