- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为图像分配字母或数字,例如字母:“A”是带有A的图像,数字“0”是带有0的图像等等。我想询问输入一个数字,例如 0,python 会将该数字链接到正确的图像(带有 0 的图像)并将该图像粘贴到空白图像。
我已经知道如何将图像与另一个图像合并(或组合),我使用 Pillow:
from PIL import Image
background_img = Image.open("blanc.png") # the blanc image
IM0 = Image.open("0.jpg") # The image with a 0
area2 = (0, 208) # Where the 0 will go on the blanc image
background_img.paste(IM0, area2) # Paste the 0
background_img.save("Final.png") # Save the final image
我知道如何通过输入来提问
number = input("what number do you want ?")
但我不知道如何将我将在输入中写入的数字分配(或链接)到特定图像..
有人可以帮我吗?
最佳答案
从代码的外观来看,缺少的只是图像的名称。例如,如果用户输入了值“1”,则需要查找名称为“1.jpg”的图像。
如果这是正确的,您可以通过以下方式轻松完成:
file_name_fmt = "{v}.jpg"
val = input()
file_name = file_name_fmt.format(v=val)
if file_name in list_of_images:
img = Image.open(file_name)
编辑
from PIL import Image
file_name_fmt = "{v}.jpg"
area2 = (0, 208) # Where the 0 will go on the blanc image
background_img = Image.open("blanc.png") # the blanc image
val = input("Enter a character for an image representation: ")
file_name = file_name_fmt.format(v=val)
if file_name in list_of_images:
img = Image.open(file_name)
else:
raise FileNotFoundError("The file specified doesn't exist")
background_img.paste(img, area2) # Paste the 0
background_img.save("Final.png") # Save the final image
关于python - 我可以向用户询问一个号码,然后将对应号码的图像粘贴到空白图像中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55952629/
我想检查我的应用程序或系统中是否存在库。在 Java 中,我通常执行 System.loadlibrary,但是有谁知道 C 中类似的相应调用吗? 最佳答案 是dlopen打开一个库,dlsym 从加
我在 typescript 中输入以下内容 export type Excludable = T & { isExcluded?: boolean } 其中过滤值: export type Filte
我最近在我的应用程序中添加了一种方法,可以自动格式化 TextView ,从“50000”到“50,000”,效果绝对完美。现在我遇到的问题是,在我的应用程序中,有多个按钮功能可以从该 TextVie
SELECT * FROM conversations WHERE chatMembers LIKE '%1%'AND chatMembers LIKE '%10%' 对话表 id | chatMem
我正在编写一个需要将 Java Date() 值保存到 MySQL 数据库的 RESTful Web 服务,但是,我不确定 MySQL 中可以保存 Java Date() 的数据类型是什么,或者我是否
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
同样,在任何 Red Hat 或 JBoss 站点上都没有关于此的信息,所以我在这里问... 我不确定是 13 还是 14。 最佳答案 Mapping the Community versions w
我曾尝试使用 swift 开发一款利用 iPhone 的 3D 触摸硬件的游戏。然而,当我将我的应用程序提交到 App Store 时,它被拒绝了,因为该游戏无法在 iPad 上玩。 我的问题是,
Qt 的有序关联容器对应项 std::map是QMap , std::set是QSet , 对于无序关联容器 std::unordered_map是QHash . 我应该用什么来代替std::unor
JavaScript 方法 String.fromCharCode() 在以下意义上与 Python 的 unichar() 等效: print unichr(213) # prints Õ on t
正如谷歌在 "Discontinuing support for JSON-RPC and Global HTTP Batch Endpoints" 中提到的那样,Google API 客户端库已重新
我正在使用 MapLayer 和 MapOverlay 在 map 中创建自己的路径/折线,GPS 捕获的所有点都存储在一个结构中,以便我可以访问它们。随时。 现在,我希望路径在用户操作 map (缩
我们使用 Adobe Flash Builder 创建由 Flex 提供支持的交互式 Web 应用程序。现在我们正在寻找替代方案,让我们在 UI 设计和迎合 HTML5 的编码方面拥有同样的开发便
我想知道Android/Java 中类似C#/C++ 中的GetTickCount 方法的相应方法吗? 最佳答案 Android 为 SystemClock.uptimeMillis() .请注意,u
我用 Vue + Phaser 开始了新项目,但是当我尝试加载 Assets 时,this.game.load.image 中的“load”和“add”返回“undefined”。我尝试从 JS 文件
我是一名优秀的程序员,十分优秀!