我有一张图片,我将链接和文本与 html 图像映射放在一起。那很好用。我想对图像的特定区域有一些悬停效果。例如,拿一张世界地图,当您将鼠标悬停在一个国家/地区上方时,该国家/地区会突出显示。使用 html 图像 map 和一些 css 这不是问题,也就是说,如果您有所有国家/地区的所有多边形坐标的列表。
那么我如何获得这些呢?您不可能手动执行此操作。
我不是 Photoshop 专家,但我想您会在一个区域上进行“魔术棒”选区,然后以某种方式列出用于创建选区的坐标。有没有这样的功能?
我个人使用 Paint.Net 进行简单的图像编辑,它没有我所知道的那个功能。
你知道怎么做吗?
我将告诉您如何使用 JavaScript 完成此操作,因为这是一个编程问答网站。
获取选择范围的直 Angular 坐标最简单:
#target photoshop
// Save the current unit preferences (optional)
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
// Set units to PIXELS
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
// Use the top-most document
var doc = app.activeDocument;
var coords = doc.selection.bounds;
// Write coords to textfile on the desktop. Thanks krasatos
var f = File( '~/Desktop/coords.txt' );
f.open( 'w' );
f.write( coords );
f.close();
// Reset to previous unit prefs (optional)
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
这将给出当前事件文档中所选内容的矩形边界(想想您在转换时看到的边界框)。它按 minX、minY、maxX、maxY 的顺序输出。这应该足以转换为 CSS 坐标。
要获取单个多边形点的坐标,您可以将选区放入路径并使用以下脚本输出路径上的每个 pathPoint.anchor:
#target photoshop
// Save the current unit preferences (optional)
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
// Set units to PIXELS
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
// Use the top-most document
var doc = app.activeDocument;
// Turn the selection into a work path and give it reference
doc.selection.makeWorkPath();
var wPath = doc.pathItems['Work Path'];
// This will be a string with the final output coordinates
var coords = '';
// Loop through all path points and add their anchor coordinates to the output text
for (var i=0; i<wPath.subPathItems[0].pathPoints.length; i++) {
coords += wPath.subPathItems[0].pathPoints[i].anchor + "\n";
}
// Write coords to textfile on the desktop. Thanks krasatos
var f = File( '~/Desktop/coords.txt' );
f.open( 'w' );
f.write( coords );
f.close();
// Remove the work path
wPath.remove();
// Reset to previous unit prefs (optional)
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
说明:
-打开你的 map 图片
-使用您最喜欢的选择工具选择区域
-使用 extendscript 工具包或通过选择"file">“脚本”>“浏览...”运行脚本,然后选择保存脚本的 .jsx 文件。