- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于标题,这是代码(由 Automate the Boring Stuff 提供),我对其进行了一些微调。
import os
from PIL import Image
SQUARE_FIT_SIZE = 300
LOGO_FILENAME = 'catlogo.png'
logoIm = Image.open(LOGO_FILENAME)
logoWidth, logoHeight = logoIm.size
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not (filename.endswith('.png') or filename.endswith('.jpg')) \
or filename == LOGO_FILENAME:
continue # skip non-image files and the logo file itself
im = Image.open(filename)
width, height = im.size
# Add logo.
print('Adding logo to %s...' % (filename))
im.paste(logoIm, (width - logoWidth, height - logoHeight), logoIm)
# Save changes.
im.save('Cat with Logo.png')
由于某些原因,最后添加logo失败。 save
命令有问题吗?
最佳答案
我意识到 resizeAndAddLogo.py
会调整粘贴 Logo 的文件的大小,而不是调整与文件成比例的 Logo 大小。我们不想要那样。所以我更改了脚本以将 Logo 大小更改为图像文件的 1/5 比例。
...
# Resize the logo.
print(f'Resizing logo to fit {filename}...')
sLogo = logoIm.resize((int(width / 5), int(height / 5)))
sLogoWidth, sLogoHeight = sLogo.size
# Add the logo.
print(f'Adding logo to {filename}...')
im.paste(sLogo, (width - sLogoWidth, height - sLogoHeight), sLogo)
...
此时,我不需要SQUARE_FIT_SIZE = 300
,所以我删除了它并使代码更短。这是我的完整脚本。
import os
from PIL import Image
LOGO_FILENAME = 'catlogo.png'
logoIm = Image.open(LOGO_FILENAME)
os.makedirs('withLogo', exist_ok=True)
# Loop over all files in the working directory.
for filename in os.listdir():
if not (filename.endswith('.png') or filename.endswith('.jpg')) or filename == LOGO_FILENAME:
continue
im = Image.open(filename)
width, height = im.size
# Resize the logo.
print(f'Resizing logo to fit {filename}...')
sLogo = logoIm.resize((int(width / 5), int(height / 5)))
sLogoWidth, sLogoHeight = sLogo.size
# Add the logo.
print(f'Adding logo to {filename}...')
im.paste(sLogo, (width - sLogoWidth, height - sLogoHeight), sLogo)
# Save changes.
im.save(os.path.join('withLogo', filename))
请注意,应分配调整大小的 Logo 以在循环中使用。
这是生成的图像之一。
关于python - 在 Python 中将 Logo 添加到猫图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51995182/
有使用过 Linux 系统的小伙伴,肯定会使用过 cat 这个命令。当然,在 Linux 下,此猫非彼猫,这里的 cat 并不代表猫,而是单词 concatenate 的缩写。 cat 命令是一个
Closed. This question needs to be more focused。它当前不接受答案。
我知道我可以穿越 List秒 import cats.instances.list._ import cats.syntax.traverse._ def doMagic(item: A): M[B]
标准库在List上提供了unzip方法: scala>val l = List((1, "one"), (2, "two"), (3, "three"), (4, "four"), (5, "five
我正在经历https://www.scala-exercises.org/对于猫来说。我想我明白Apply.ap 是什么意思。但我看不到它有任何用途。 有什么区别: Apply[Option].map
我是 cat 和函数式编程方面的新手,我正在努力对 EitherT 等函数式数据类型进行单元测试。有示例代码: class Library[F[_]]() { def create(book:
基本上我试图理解这些命令之间的区别: cat >(tee f.txt) echo yolo > >(tee t.txt) 前两个命令具有完全相同的结果:打印“yolo”,然后终端返回控制权,这正是我
我正在经历https://www.scala-exercises.org/对于猫来说。我想我明白Apply.ap 是什么意思。但我看不到它有任何用途。 有什么区别: Apply[Option].map
我是 cat 和函数式编程方面的新手,我正在努力对 EitherT 等函数式数据类型进行单元测试。有示例代码: class Library[F[_]]() { def create(book:
给定: import cats.syntax.cartesian._ type M[X] = Future[Either[Error, X]] val ma: M[A] = ??? val mb: M
我想使用来自该存储库的 cats-saga:https://github.com/VladKopanev/cats-saga 但是我卡在了 OrderSagaCoordinator.scala L16
假设我有: val x1: Either[String, Int] = Right(1) val x2: Either[String, Float] = Left("Nope") val x3: Ei
我正在重新编码 printf,我从 printf 获得的行为与真正的 printf 略有不同,因为我使用字符串(即 malloc),而真正的 printf 使用写入函数。 做的时候: ./a.out
这个问题在这里已经有了答案: What is PECS (Producer Extends Consumer Super)? (16 个答案) 关闭 5 年前。 这不是一个重复的问题,因为我特别询问
好的,所以我会更具体一些(自从我上一个问题以来)。 基本上,我有一个分页页面 - 有 3 个显示类别,但每个分页页面仅显示 50 个项目。因此,您可以获取占据一页的所有单个类别,或不同类别的组合 -
我在“Abb/test”文件夹中有一些 c 文件和 common.txt,在“Abb”文件夹中有 temp.txt。我想在所有 c 文件的标题中复制 common.txt 的内容。我正在使用以下 un
我有以下脚本 #!/bin/bash set i=0; while read line do echo "$line"; $i INFO 2013-08-16 13:46:48,660 In
我正在尝试为猫寻找一个例子 EitherT.collectRight 。我有一个EitherT[Future, String, Event]当我这样做时collectRight,我明白了 Error:
我有这段代码可以编译并且工作正常 import cats.implicits._ Cartesian[ValidResponse].product( getName(map).toValida
我有两个相同的文件,但它们的大小不同。这让我想到文件中有特殊字符,即 ^M 在第六章中 :set list 不显示 ^M 字符但是 cat -A 确实显示字符。 此外,VI 仅在出现在行尾时才显示特殊
我是一名优秀的程序员,十分优秀!