获取图像特定区域的所有多边形坐标?

问题描述:

我有一个图像是我把链接和文字与HTML图像映射。这工作正常。我想对图片的特定区域产生一些悬停效果。例如,拿一张世界地图,当你悬停在一个突出显示的国家时。有了html图像映射和一些css,这不是一个问题,也就是说,如果你有一个所有国家的所有多边形坐标列表。获取图像特定区域的所有多边形坐标?

那么我该如何获得这些?你不可能手动做到这一点。

我不是一个photoshop专家,但我想你会做一个“魔杖”选择的区域,然后以某种方式列出用于创建选择的坐标。有没有这样的功能?

我个人使用Paint.Net进行简单的图像编辑,它没有我所知道的那个特征。

你知道怎么做吗?

+0

好问题,来自我的投票。 – Hoque 2011-12-19 07:47:08

+0

所以你想要的东西有点像[这](http://davidlynch.org/projects/maphilight/docs/demo_world.html)?我会考虑使用诸如Java或jQuery之类的东西。也许,看看[这里](http://davidlynch.org/projects/maphilight/docs/)。我不知道它是否会有所帮助,但它是一些东西。 – ACarter 2011-12-20 14:05:24

ps中没有任何选项,您必须在Dreamweaver中创建坐标。

我会告诉你如何用JavaScript做到这一点,因为这是一个编程Q/A网站。

为了让选择范围的直角坐标是最简单的:

#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; 

说明:

-open地图图像

-make使用您喜欢的选择工具

-run与extendscript脚本也选择区域lkit或通过选择文件>脚本>浏览...并选择保存脚本的.jsx文件。