ps一键去除gif背景的jsx脚本

本文介绍了一种使用Photoshop的JSX脚本方法,能够便捷地去除GIF图像的背景,提高了处理动态图的工作效率。

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

// 本脚本为肖老师原创,可快速去除GIF动图背景,使用或者转载,请注明出处!
var myDoc = app.activeDocument;

function RMLayerBG() {
	var feather = 0;
	var antiAlias = true;
	for (var i = 1; i < myDoc.artLayers.length + 1; i++) {
		SelectAndRemoveBGArea(i);
	}
}

function SelectAndRemoveBGArea(layerNum) {

	// 选择时间轴上的图层
	var dTimeline = new ActionDescriptor();
	var rTimeline = new ActionReference();
	rTimeline.putIndex(stringIDToTypeID("animationFrameClass"), layerNum);
	dTimeline.putReference(stringIDToTypeID("null"), rTimeline);
	executeAction(stringIDToTypeID("select"), dTimeline, DialogModes.NO);

	// 选择图层面板上的图层
	var dLayer = new ActionDescriptor();
	var rLayer = new ActionReference();
	rLayer.putName(stringIDToTypeID("layer"), "图层 " + layerNum);
	dLayer.putReference(stringIDToTypeID("null"), rLayer);
	dLayer.putBoolean(stringIDToTypeID("makeVisible"), false);
	var list = new ActionList();
	list.putInteger(4);
	dLayer.putList(stringIDToTypeID("layerID"), list);
	executeAction(stringIDToTypeID("select"), dLayer, DialogModes.NO);

	// 选择当前图层主体
	var dSelect = new ActionDescriptor();
	dSelect.putBoolean(stringIDToTypeID("sampleAllLayers"), false);
	executeAction(stringIDToTypeID("autoCutout"), dSelect, DialogModes.NO);
	// 反选
	myDoc.selection.invert();
	// WandSelect();
	myDoc.selection.clear();
	myDoc.selection.deselect();
}

function WandSelect() {
	var d = new ActionDescriptor();
	var r = new ActionReference();
	r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
	d.putReference(stringIDToTypeID("null"), r);
	var d1 = new ActionDescriptor();
	d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 20);//水平像素点位置
	d1.putUnitDouble(stringIDToTypeID("vertical"), stringIDToTypeID("pixelsUnit"), 20);//垂直像素点位置
	d.putObject(stringIDToTypeID("to"), stringIDToTypeID("point"), d1);
	d.putInteger(stringIDToTypeID("tolerance"), 5);
	d.putBoolean(stringIDToTypeID("antiAlias"), true);
	executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}
RMLayerBG();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值