コード例 #1
0
ファイル: export.py プロジェクト: jonoxia/pencilbox
def compositeFiles(artist, fileNameList, outFileName):
  tmp_dir = get_dir_for_artist(artist, "tmp")
  pub_dir = get_dir_for_artist(artist, "pub")
  baseImage = Image.open( os.path.join(tmp_dir, fileNameList[0]) )
  for fileName in fileNameList[1:]:
    layerImage = Image.open( os.path.join(tmp_dir, fileName) )
    baseImage.paste(layerImage, (0, 0), layerImage)
  baseImage.save( os.path.join(pub_dir, outFileName ))
コード例 #2
0
ファイル: upload.py プロジェクト: jonoxia/pencilbox
def uploadFromClient(fileitem):
    # Test if the file was uploaded
    if fileitem.filename:
        # Don't care about original filename; make a new one up
        # that way we don't have to worry about spaces, collisions, etc
        filename = createUniqueFilename(fileitem.filename)
        tmp_dir = get_dir_for_artist(artist, "tmp")
        file = open(os.path.join(tmp_dir, filename), "wb")
        file.write(fileitem.file.read())
        file.close()
        url = TMP_FILE_URL % (str(artist.id), filename)
        return url
    else:
        return False
コード例 #3
0
ファイル: export.py プロジェクト: jonoxia/pencilbox
def writeTempFiles(artist, dataBlob, outFileName):
  tmp_dir = get_dir_for_artist(artist, "tmp")
  layerBlobs = dataBlob.split(",")
  filenames = []
  for i in xrange(len(layerBlobs)):
    data = layerBlobs[i]
    filename = "layer%d-%s" % (i, outFileName)
    filenames.append(filename)
    file = open( os.path.join(tmp_dir, filename), "wb")
    # Get an "incorrect padding" error on trying to decode.
    # Correct b64 padding:
    while len(data) % 4 != 0:
      data = data + "="
    file.write(base64.b64decode(data))
    file.close()

  return filenames
コード例 #4
0
ファイル: upload.py プロジェクト: jonoxia/pencilbox
def sideloadFromWeb(url):
    # TODO need to think about security - can someone f**k up my server
    # by using the url import to force it into downloading some bad
    # juju?
    response = urllib2.urlopen(url)
    data = response.read()
    # TODO how big a file will this work on?  might we need to stream
    # it for larger files?
    response.close()
  
    filename = createUniqueFilename(url.split("/")[-1])
    tmp_dir = get_dir_for_artist(artist, "tmp")

    file = open(os.path.join(tmp_dir, filename), "wb")
    file.write(data)
    file.close()
    url = TMP_FILE_URL % (str(artist.id), filename)
    return url