在PS中用脚本实现将不同的二维码和文字批量处理到相同的一张图片上

本文详细描述了如何在AdobePhotoshop中使用JavaScript脚本,通过批量处理将不同大小和位置的二维码以及文字添加到同一张图片上的步骤,包括选择文件、定位、编辑文本和保存结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求描述:

在PS中用脚本实现将不同的二维码和文字批量处理到相同的一张图片上

结果呈现:

实现步骤:

请注意,这个过程假设所有的二维码都是同样的大小,而且你想要将它们放在同样的位置。如果你需要将二维码放在不同的位置,或者如果你的二维码有不同的大小,那么你可能需要创建多个动作,或者手动调整每个二维码。

在Adobe Photoshop中使用JavaScript脚本的步骤如下:

  1. 创建脚本:首先,你需要使用任何文本编辑器(如Notepad,Sublime Text,VS Code等)创建一个JavaScript文件。在这个文件中,你可以写入你的Photoshop脚本。保存这个文件时,你需要使用.js作为文件扩展名。当然这里你可以直接使用我的脚本,只需更换一下相应文件的路径。

  2. 打开Photoshop:启动Adobe Photoshop程序。

  3. 运行脚本:在Photoshop中,点击左上角的 "文件(File)" 菜单,然后选择"脚本(Scripts)" ,点击下方的 "浏览(Browse)" 。在弹出的文件选择对话框中,找到并选择你的.js脚本文件,然后点击Open按钮。这将会运行你的脚本。

相关的文件夹:

脚本代码:

var sourceFolder = Folder.selectDialog("Select the folder with your QR codes");
var files = sourceFolder.getFiles("*.png");  // Assumes the QR codes are PNG files

// Assume the texts are stored in a text file, one text per line
var textFile = File('D:/你的文件夹名称/99 Logo/Microsoft.csv');  // Replace with the path to your text file
textFile.open('r');
var texts = [];
while (!textFile.eof) {
    texts.push(textFile.readln().split(','));  // Split each line into name and phone number
}
textFile.close();

var doc = app.open(File('D:/你的文件夹名称/99 Logo/picture01.png'));  // Replace with the path to your image

var targetX = 200;  // Replace with the x-coordinate of the target position
var targetY = 450;  // Replace with the y-coordinate of the target position

var textLayer;  // Declare textLayer variable here

for (var i = 0; i < files.length; i++) {
    // Reset the textLayer to undefined at the start of each iteration
    textLayer = undefined;

    var qr = app.open(files[i]);

    app.activeDocument.selection.selectAll();
    app.activeDocument.selection.copy();
    qr.close(SaveOptions.DONOTSAVECHANGES);  // Do not save changes

    doc.paste();
	
	doc.activeLayer.resize(30, 30, AnchorPosition.MIDDLECENTER);  // Resize the QR code to 100px by 100px

    //doc.activeLayer.resize(20, 20, AnchorPosition.MIDDLECENTER);  // Adjust as needed to resize the QR code
    doc.activeLayer.translate(100, 100);  // Adjust as needed to position the QR code
    var dx = targetX - doc.activeLayer.bounds[0].as('px');
    var dy = targetY - doc.activeLayer.bounds[1].as('px');
    doc.activeLayer.translate(dx, dy);

    if (textLayer !== undefined) {
        textLayer.remove();  // Remove the text layer from the previous iteration
    }

    // Create a new text layer
    textLayer = doc.artLayers.add();
    textLayer.kind = LayerKind.TEXT;

    // Set the text content, if it exists, otherwise set a default value
    if (texts[i] !== undefined) {
        textLayer.textItem.contents = texts[i][0] + "\r" + texts[i][1];  // Set the text to name and phone number
    } else {
        textLayer.textItem.contents = "Default name\nDefault phone number";  // Set a default text
    }

    // Set the font and size of the text
    textLayer.textItem.font = "Arial";  // Set the font to Arial
    textLayer.textItem.size = 5;  // Set the size to 12
	
	// Set the position of the text layer
	textLayer.textItem.position = [40, 500];  // Replace with the target position for the text

    // Create a new solid color and set its RGB values
    var myColor = new SolidColor();
    myColor.rgb.red = 255;
    myColor.rgb.green = 255;
    myColor.rgb.blue = 255;

    // Set the color of the text
    textLayer.textItem.color = myColor;

    var saveFile = File('D:/你的文件夹名称/99 Logo/2024年2月26日' + '/image' + i + '.png');  // Replace with the path to your save folder
    var saveOptions = new PNGSaveOptions();  // Assumes you want to save as PNG
    doc.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);

    doc.activeLayer.remove();  // Remove the QR code layer for the next iteration
}

doc.close(SaveOptions.DONOTSAVECHANGES);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值