Esempio n. 1
0
	def save(self, *args, **kwargs):
		""" 
		Save the Crop object, and create the thumbnails by creating 
		one rescaled version for each ratio and then resizing for each 
		thumbnail within that ratio
		"""
		super(Crop, self).save(*args, **kwargs)

		if self.size:
			# get all the manually cropped sizes with the same aspect ratio as this crop/size
			sizes = Size.objects.all().filter(
				aspect_ratio=self.size.aspect_ratio, 
				size_set=self.size.size_set,
				auto_size=0,
			).order_by("-width")
			
			if sizes:
				# create the cropped image 
				cropped_image = utils.create_cropped_image(
					self.image.path, 
					self.crop_x, 
					self.crop_y, 
					self.crop_w, 
					self.crop_h
				)
				
				# loop through the other sizes of the same aspect ratio, and create those crops
				for size in sizes:
					self.image.rescale(cropped_image, size=size)
Esempio n. 2
0
	def save(self, *args, **kwargs):
		super(Crop, self).save(*args, **kwargs)

		if self.size:
			sizes = Size.objects.all().filter(aspect_ratio=self.size.aspect_ratio, size_set=self.size.size_set).exclude(auto_size=1).order_by("-width")
			if sizes:
				cropped_image = utils.create_cropped_image(self.image.image.path, self.crop_x, self.crop_y, self.crop_w, self.crop_h)
					
				for size in sizes:
					
					thumbnail = utils.rescale(cropped_image, size.width, size.height, crop=size.auto_size)
	
					if not os.path.exists(self.image.folder_path):
						os.makedirs(self.image.folder_path)
					
					thumbnail.save(self.image.thumbnail_path(size), **IMAGE_SAVE_PARAMS)
Esempio n. 3
0
	def create_thumbnail(self, size, force_crop=False):
		""" Creates a thumbnail for an image at the specified size """
	
		if not size.auto_size:
			try:
				crop = self.get_crop(size)
				
				cropped_image = utils.create_cropped_image(
					self.image.path, 
					crop.crop_x, 
					crop.crop_y, 
					crop.crop_w, 
					crop.crop_h
				)
			except Crop.DoesNotExist:
				# auto-crop if no crop is defined
				cropped_image = pil.open(self.image.path)
		else:
			cropped_image = pil.open(self.image.path)
		
		self.rescale(cropped_image=cropped_image, size=size, force_crop=force_crop)