我和我的搭档开始使用Pillow创建照片处理程序的项目。我们当前的目标是将苹果徽标的蒙版粘贴到另一个图像上,以对其进行整形。
事实证明,枕头对我和她来说都非常荒唐,我们已经到了需要帮助的地步。
这是当前代码基于我们老师给我们的代码。每次运行时,都会出现ValueError:图像不匹配。错误消息也在下面。
Names = c("eggs","milk","bread","I need to make some names longer")
Kilos = c("1","2","3","4")
df= as.data.frame(cbind(Names,Kilos))
plot_citation = "I need to include the citation for my data in the plot itself.
Some of the citations are long, so they
take up
several lines."
TestGGPlot = ggplot(df,aes(y = Kilos, x = Names, fill = Names))+
geom_bar(stat = "identity")+
scale_fill_manual(values = c("#ABCABC","#ABCABC","#ABCABC","#ABCABC"))+
theme(legend.position = "none")+
coord_flip()+
xlab("Names")+
ylab("Kilos")+
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background = element_blank(),axis.ticks.y=element_blank())+
labs(caption = plot_citation,vjust=1,hjust=1)+
theme(plot.caption=element_text(hjust=0))
TestGGPlot
TestPlotly = ggplotly(TestGGPlot)
TestPlotly
错误消息:
from __future__ import print_function
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os.path
import PIL
import PIL.ImageDraw
def apple_logo(original_image):
width, height = original_image.size
apple = PIL.Image.open('logo.jpg')
apple.resize((width, height))
apple.load()
result = PIL.Image.new('RGBA', original_image.size, (0,0,0,0))
result.paste(original_image, (0,0), mask=apple)
return result
def get_images(directory=None):
if directory == None:
directory = os.getcwd() # Use working directory if unspecified
image_list = [] # Initialize aggregaotrs
file_list = []
directory_list = os.listdir(directory) # Get list of files
for entry in directory_list:
absolute_filename = os.path.join(directory, entry)
try:
image = PIL.Image.open(absolute_filename)
file_list += [entry]
image_list += [image]
except IOError:
pass # do nothing with errors tying to open non-images
return image_list, file_list
def apple_logo_all(directory=None):
if directory == None:
directory = os.getcwd() # Use working directory if unspecified
# Create a new directory 'modified'
new_directory = os.path.join(directory, 'modified')
try:
os.mkdir(new_directory)
except OSError:
pass # if the directory already exists, proceed
# Load all the images
image_list, file_list = get_images(directory)
# Go through the images and save modified versions
for n in range(len(image_list)):
# Parse the filename
print(n)
filename, filetype = os.path.splitext(file_list[n])
# Round the corners with default percent of radius
curr_image = image_list[n]
new_image = apple_logo(curr_image)
# Save the altered image, suing PNG to retain transparency
new_image_filename = os.path.join(new_directory, filename + '.png')
new_image.save(new_image_filename)
apple_logo_all()
很抱歉打扰。我们似乎无法弄清楚。
谢谢:)
-J