【发布时间】:2011-09-19 16:03:07
【问题描述】:
我有谷歌地图图标,在使用MarkerImage 在地图上绘图之前,我需要将其旋转一定角度。我使用 PIL 在 Python 中即时进行旋转,生成的图像与原始图像大小相同 - 32x32。例如,使用以下默认 Google 地图标记: ,使用以下python代码实现逆时针旋转30度:
# full_src is a variable holding the full path to image
# rotated is a variable holding the full path to where the rotated image is saved
image = Image.open(full_src)
png_info = image.info
image = image.copy()
image = image.rotate(30, resample=Image.BICUBIC)
image.save(rotated, **png_info)
生成的图像是
当使用新的旋转图像创建 MarkerImage 时,棘手的一点是要使用新的锚点。这需要是图标的尖端。默认情况下,锚点位于底部中间[定义为 x,y 坐标中的 (16,32),其中 (0,0) 是左上角]。有人可以向我解释一下如何在 JavaScript 中轻松解决这个问题吗?
谢谢。
2011 年 6 月 22 日更新: 发布了错误的旋转图像(原始图像是逆时针旋转 330 度)。我已经纠正了。还添加了重采样(Image.BICUBIC),使旋转的图标更清晰。
【问题讨论】:
-
@Trufa:感谢您的建议。
标签: javascript python api google-maps image-rotation