Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def main():
- image = pickAFile() #pick the file
- #imgCheck(image)
- fileSize(image)
- # Pick the file and pass it on to the next part
- #def imgCheck(image): #check for all image extensions compatible with python
- #here you need to do the checks on whether the file picked is a file compatible with jython
- # try:
- #some code here that will throw an exception if an incompatible file is tried, i recommend getHeight(makePicture(image))
- # except:
- #show an error message: showInformation("error") etc
- # else:
- # fileSize(image)
- def fileSize(image): # find the size of the file, dale already gave us this code
- fileStats = os.stat(image)
- fsize = fileStats.st_size
- numberSlices(fsize, image)
- def numberSlices(fsize, image): #find the number of slices needed to keep each slice below 20000bytes
- sliceLimit = 20000
- numberSlices = (fsize / sliceLimit) + 1 #add 1 such that uneven divisions will always result in a slice size less than 20000 bytes
- showInformation("Number of Slices:" + str(numberSlices))
- if numberSlices == 1:
- showInformation("This image does not need to be split and can be uploaded")
- else:
- fileExtension(numberSlices, image)
- def fileExtension(numberSlices, image):
- #find the file extension and the file path minus the extension
- fileExtension = os.path.splitext(image)[1]
- filePath = os.path.splitext(image)[0]
- splitImage(numberSlices, image, fileExtension, filePath)
- def splitImage(numberSlices, image, fileExtension, filePath): #time to split the image, into noSlices many pieces
- pic = makePicture(image)
- imageOrder = 0 #number each file in the order it is saved
- imageHeight = getHeight(pic)
- imageWidth = getWidth(pic)
- imageX = 0 #x pixel coordinate
- imageY = 0 #y pixel coordinate this has to increment
- splitHeight = imageHeight / (numberSlices)
- imgHeight = splitHeight
- for imageOrder in range(0, (numberSlices)):
- canvas = makeEmptyPicture(imageWidth,splitHeight)
- fileName = (filePath + "_" + str(imageOrder) + "_" + str(numberSlices) + fileExtension)
- for sourceX in range(0, imageWidth):
- for sourceY in range(imageY, imgHeight):
- color = getColor(getPixel(pic, sourceX, sourceY))
- setColor(getPixel(canvas, sourceX, sourceY), color)
- writePictureTo(canvas, fileName)
- imageY = imageY + splitHeight
- imgHeight = imgHeight + splitHeight
- imageOrder = imageOrder + 1
- #loop for the last slice starts here this has 2 loops as well.
- #you need to find the height of the last slice in pixels. I used lastHeight = imageHeight - (splitHeight * (numberslices - 1))
- #then specify the fileName again because its a variable
- #canvas = #make the canvas again but this time with the new split height
- #then start the copy function again and make sure you use the right y axis pixels.... think about this.
- #writePictureTo(canvas, fileName)
- print "all done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement