我无法弄清楚如何更改此代码上的文件路径?
import os
import glob
import time
import traceback
from time import sleep
import RPi.GPIO as GPIO
import picamera
import atexit
import sys
import socket
import pygame
from pygame.locals import QUIT, KEYDOWN, K_ESCAPE
import pytumblr
import config
from signal import alarm, signal, SIGALRM, SIGKILL
from os.path import join, basename, expanduser
from PIL import Image
def watermark(image):
""" Apply a watermark to an image """
mark = Image.open(watermark_img)
im = Image.open(image)
if im.mode != 'RGBA':
im = im.convert('RGBA')
layer = Image.new('RGBA', im.size, (0,0,0,0))
position = (im.size[0] - mark.size[0], im.size[1] - mark.size[1])
layer.paste(mark, position)
outfile = join(basename(image))
Image.composite(layer, im, layer).save(outfile)
return outfile
我希望它转到:/home/pi/photobooth/pics/
或同一地点的config.file_path
。
答案 0 :(得分:0)
好的,所以我已经阅读了PIL的文档(一切都符合预期),你应该尝试:
outfile = join( <your_path> , basename(image) ) # replace your_path to actual path
Image.composite(layer, im, layer).save(outfile)