當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageUtils.create_thumbnail方法代碼示例

本文整理匯總了Python中ImageUtils.ImageUtils.create_thumbnail方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageUtils.create_thumbnail方法的具體用法?Python ImageUtils.create_thumbnail怎麽用?Python ImageUtils.create_thumbnail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ImageUtils.ImageUtils的用法示例。


在下文中一共展示了ImageUtils.create_thumbnail方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_existing_image

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
	def add_existing_image(self, user, oldimage, oldpath, subdir='', album_id=-1):
		if 'tumblr' in oldpath:
			# Can't properly handle tumblr links
			self.debug('cannot properly handle tumblr links; trying anyway')
			#return
		if subdir == '' and album_id == -1:
			self.debug('adding image: %s' % oldpath)
		# Ensure image is an actual image
		try:
			dims = ImageUtils.get_dimensions(oldpath)
		except:
			self.debug('failed to load image: %s, skipping' % oldpath)
			return
		newimage  = path.join(ImageUtils.get_root(), 'content', user, subdir, oldimage)
		newimage = newimage.replace('.jpeg.jpg', '.jpg')
		thumbnail = path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs', oldimage)
		thumbnail = thumbnail.replace('.jpeg.jpg', '.jpg')
		if path.exists(newimage):
			self.debug('new image already exists: %s' % newimage)
			return

		ImageUtils.create_subdirectories(path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs'))

		copy2(oldpath, newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception, e:
			self.debug('failed to create thumbnail: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
開發者ID:PlopFriction,項目名稱:gonewilder,代碼行數:31,代碼來源:DB.py

示例2: backfill_videos

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
def backfill_videos():
	query = '''
		select id, path, thumb
			from images
			where type = 'video'
				and
				(
					thumb like '%.mp4'
				or
					thumb like '%.flv'
				or
					thumb like '%.wmv'
				)
	'''
	cur = db.conn.cursor()
	for imgid, image, oldthumb in cur.execute(query).fetchall():
		saveas = oldthumb
		saveas = '%s.png' % saveas[:saveas.rfind('.')]
		try:
			newthumb = ImageUtils.create_thumbnail(image, saveas)
		except Exception as e:
			print('ERROR: %s' % str(e))
			continue
		print('replacing %s with %s' % (oldthumb, newthumb))
		q = '''
			update images
				set
					thumb = ?
				where
					id = ?
		'''
		cur.execute(q, (newthumb, imgid))
		db.commit()
		print('removing %s...' % oldthumb),
		osremove(oldthumb)
		print('removed')
	cur.close()
開發者ID:gwely,項目名稱:Redownr,代碼行數:39,代碼來源:Backfill.py

示例3: start

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
	def start(self):
		'''
			Overriding SiteBase's start() method for unique ripping logic
		'''
		# We need a lot of libraries
		from ImageUtils import ImageUtils
		from calendar import timegm
		from shutil import copy2, rmtree
		from time import gmtime
		from os import path, walk, environ, getcwd
		from json import loads

		savedir = path.join('rips', self.path)
		if getcwd().endswith('py'):
			savedir = path.join('..', savedir)

		if self.album_exists:
			# Don't re-rip an album. Return info about existing album.
			return {
				'warning'  : 'album already exists',
				'album_id' : self.album_id,
				'album'    : self.album_name,
				'url'      : self.url,
				'host'     : self.get_host(),
				'path'     : self.path,
				'count'    : self.db.count('medias', 'album_id = ?', [self.album_id]),
				'pending'  : self.db.count('urls', 'album_id = ?', [self.album_id])
			}

		user = self.url.split(':')[-1]

		# Search for username (with proper case) on site
		gwapi = self.db.get_config('gw_api')
		if gwapi == None:
			raise Exception('unable to rip gonewild albums: gw_api is null')
		r = self.httpy.get('%s?method=search_user&user=%s' % (gwapi, user))
		json = loads(r)
		found = False
		for jsonuser in json['users']:
			if jsonuser.lower() == user.lower():
				found = True
				user = jsonuser
				break

		gwroot = self.db.get_config('gw_root')
		if gwroot == None:
			raise Exception('unable to rip gonewild albums: gw_root is null')
		userroot = path.join(gwroot, user)
		# Check if we can actually rip this user
		if not found or not path.exists(userroot):
			return {
				'error' : 'unable to rip user (not archived)'
			}

		# Create subdirs
		ImageUtils.create_subdirectories(path.join(savedir, 'thumbs'))

		# Copy images to /rips/, get values that need to be inserted into db (insertmany)
		insertmany = []
		already_got = []
		filesize = 0
		for root, subdirs, files in walk(userroot):
			if root.endswith('thumbs'): continue
			for filename in sorted(files):
				f = path.join(root, filename)
				n = filename
				if not root.endswith(userroot):
					# It's a subidr, save the file accordingly
					n = '%s_%s' % (root[root.rfind('/')+1:], filename)

				# Avoid duplicates
				no_post = n[n.rfind('_')+1:]
				if no_post in already_got: continue
				already_got.append(no_post)

				n = '%03d_%s' % (len(insertmany) + 1, n)
				saveas = path.join(savedir, n)

				# Copy & get size
				try:
					copy2(f, saveas)
					(width, height) = ImageUtils.get_dimensions(saveas)
				except Exception, e:
					# image can't be parsed, probably corrupt. move on.
					continue

				# Create thumbnail
				tsaveas = path.join(savedir, 'thumbs', n)
				try:
					(tsaveas, twidth, theight) = ImageUtils.create_thumbnail(saveas, tsaveas)
				except Exception, e:
					# Failed to create thumb
					tsaveas = '/'.join(['ui', 'images', 'nothumb.png'])
					twidth = theight = 160

				filesize += path.getsize(saveas)
				# Add to list of values to insert into DB
				insertmany.append( [
						self.album_id,        # album_id, currently None
						len(insertmany) + 1,  # i_index
#.........這裏部分代碼省略.........
開發者ID:4pr0n,項目名稱:rip3,代碼行數:103,代碼來源:SiteGonewild.py

示例4: copy2

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
		ImageUtils.create_subdirectories(path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs'))

		copy2(oldpath, newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception, e:
			self.debug('failed to create thumbnail: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')

		(post, comment, imgid) = self.get_post_comment_id(oldimage)
		url  = 'http://i.imgur.com/%s' % imgid
		dims = ImageUtils.get_dimensions(newimage)
		size = path.getsize(newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception, e:
			self.debug('add_existing_image: create_thumbnail failed: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
		try:
			self.add_image(newimage, user, url, 
					dims[0], dims[1], size, thumbnail, 'image', 
					album_id, post, comment)
		except Exception, e:
			self.debug('add_existing_image: failed: %s' % str(e))
			return

		if subdir == '' and album_id == -1: # Not an album
			# Add post
			p = Post()
			p.id = post
開發者ID:PlopFriction,項目名稱:gonewilder,代碼行數:32,代碼來源:DB.py

示例5: format_exc

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
                format_exc(),
            )
            result["error"] = "failed to identify image file %s from %s: %s\n%s" % (
                saveas,
                url["url"],
                str(e),
                format_exc(),
            )
            self.results.append(result)
            self.current_threads.pop()
            return

            # Get thumbnail
        tsaveas = path.join(dirname, "thumbs", url["saveas"])
        try:
            (tsaveas, result["t_width"], result["t_height"]) = ImageUtils.create_thumbnail(saveas, tsaveas)
        except Exception, e:
            # Failed to create thumbnail, use default
            print "THREAD: %s: failed to create thumbnail: %s" % (url["path"], str(e))
            tsaveas = "/".join(["ui", "images", "nothumb.png"])
            result["t_width"] = result["t_height"] = 160
        result["thumb_name"] = path.basename(tsaveas)

        result["valid"] = 1
        self.results.append(result)
        self.current_threads.pop()


if __name__ == "__main__":
    rm = RipManager()
    rm.start()
開發者ID:jadedgnome,項目名稱:rip3,代碼行數:33,代碼來源:RipManager.py

示例6: str

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
				savethumbas = path.join(ImageUtils.get_root(), 'images', 'audio.png')
			else:
				try:
					(width, height) = ImageUtils.get_dimensions(saveas)
				except Exception, e:
					# If we cannot process the media file, skip it!
					self.debug('%s: process_url: #%d %s' % (child.author, media_index + 1, str(e)))
					continue

				# Create thumbnail if needed
				if self.db.get_config('save_thumbnails', 'true') == 'false':
					savethumbas = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
				else:
					savethumbas = path.join(working_dir, 'thumbs', fname)
					try:
						savethumbas = ImageUtils.create_thumbnail(saveas, savethumbas)
					except Exception, e:
						savethumbas = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
						self.debug('%s: process_url: failed to create thumb #%d: %s, using default' % (child.author, media_index + 1, str(e)))

			size = path.getsize(saveas)

			# Add to DB
			self.db.add_image(
					saveas,
					child.author,
					media,
					width,
					height,
					size,
					savethumbas,
開發者ID:4pr0n,項目名稱:gonewilder,代碼行數:33,代碼來源:Gonewild.py

示例7: add_existing_image

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
	def add_existing_image(self, user, oldimage, oldpath, subdir='', album_id=-1):
		if 'tumblr' in oldpath:
			# Can't properly handle tumblr links
			self.debug('cannot properly handle tumblr links; trying anyway')
			#return
		if subdir == '' and album_id == -1:
			self.debug('adding image: %s' % oldpath)
		# Ensure image is an actual image
		try:
			dims = ImageUtils.get_dimensions(oldpath)
		except:
			self.debug('failed to load image: %s, skipping' % oldpath)
			return
		newimage  = path.join(ImageUtils.get_root(), 'content', user, subdir, oldimage)
		newimage = newimage.replace('.jpeg.jpg', '.jpg')
		thumbnail = path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs', oldimage)
		thumbnail = thumbnail.replace('.jpeg.jpg', '.jpg')
		if path.exists(newimage):
			self.debug('new image already exists: %s' % newimage)
			return

		ImageUtils.create_subdirectories(path.join(ImageUtils.get_root(), 'content', user, subdir, 'thumbs'))

		copy2(oldpath, newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception as e:
			self.debug('failed to create thumbnail: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')

		(post, comment, imgid) = self.get_post_comment_id(oldimage)
		url  = 'http://i.imgur.com/%s' % imgid
		dims = ImageUtils.get_dimensions(newimage)
		size = path.getsize(newimage)
		try:
			ImageUtils.create_thumbnail(newimage, thumbnail)
		except Exception as e:
			self.debug('add_existing_image: create_thumbnail failed: %s' % str(e))
			thumbnail = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
		try:
			self.add_image(newimage, user, url, 
					dims[0], dims[1], size, thumbnail, 'image', 
					album_id, post, comment)
		except Exception as e:
			self.debug('add_existing_image: failed: %s' % str(e))
			return

		if subdir == '' and album_id == -1: # Not an album
			# Add post
			p = Post()
			p.id = post
			p.author = user
			if comment == None: p.url = url
			p.created = path.getctime(oldpath)
			p.subreddit = ''
			p.title = ''
			try:
				self.add_post(p, legacy=1)
			except Exception as e:
				self.debug('add_existing_image: create post failed: %s' % str(e))

			# Add comment
			if comment != None:
				c = Comment()
				c.id = comment
				c.post_id = post
				c.author = user
				if comment != None: c.body = url
				p.created = path.getctime(oldpath)
				try:
					self.add_comment(c, legacy=1)
				except Exception as e:
					self.debug('add_existing_image: create comment failed: %s' % str(e))
開發者ID:gwely,項目名稱:Redownr,代碼行數:75,代碼來源:DB.py

示例8: str

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
				self.debug('%s: process_url: failed to download #%d: %s, moving on' % (child.author, media_index + 1, str(e)))
				continue

			# Get media information (width, height, size)
			try:
				(width, height) = ImageUtils.get_dimensions(saveas)
			except Exception, e:
				# If we cannot process the media file, skip it!
				self.debug('%s: process_url: #%d %s' % (child.author, media_index + 1, str(e)))
				continue
			size = path.getsize(saveas)

			# Create thumbnail
			savethumbas = path.join(working_dir, 'thumbs', fname)
			try:
				savethumbas = ImageUtils.create_thumbnail(saveas, savethumbas)
			except Exception, e:
				savethumbas = path.join(ImageUtils.get_root(), 'images', 'nothumb.png')
				self.debug('%s: process_url: failed to create thumb #%d: %s, using default' % (child.author, media_index + 1, str(e)))

			# Add to DB
			self.db.add_image(
					saveas,
					child.author,
					media,
					width,
					height,
					size,
					savethumbas,
					media_type,
					album_id,
開發者ID:ohhdemgirls,項目名稱:gonewilder,代碼行數:33,代碼來源:Gonewild.py

示例9: str

# 需要導入模塊: from ImageUtils import ImageUtils [as 別名]
# 或者: from ImageUtils.ImageUtils import create_thumbnail [as 別名]
		result['filesize'] = path.getsize(saveas)
		try:
			(result['width'], result['height']) = ImageUtils.get_dimensions(saveas)
		except Exception, e:
			# This fails if we can't identify the image file. Consider it errored
			print 'THREAD: %s: failed to identify image file %s from %s: %s\n%s' % (url['path'], saveas, url['url'], str(e), format_exc())
			result['error'] = 'failed to identify image file %s from %s: %s\n%s' % (saveas, url['url'], str(e), format_exc())
			self.to_remove.append( (url['album_id'], url['i_index'] ) )
			self.results.append(result)
			self.current_threads.pop()
			return

		# Get thumbnail
		tsaveas = path.join(dirname, 'thumbs', url['saveas'])
		try:
			(tsaveas, result['t_width'], result['t_height']) = ImageUtils.create_thumbnail(saveas, tsaveas)
		except Exception, e:
			# Failed to create thumbnail, use default
			print 'THREAD: %s: failed to create thumbnail: %s' % (url['path'], str(e))
			tsaveas = '/'.join(['ui', 'images', 'nothumb.png'])
			result['t_width'] = result['t_height'] = 160
		result['thumb_name'] = path.basename(tsaveas)

		result['valid'] = 1
		# Delete from URLs list
		self.results.append(result)
		self.current_threads.pop()

	@staticmethod
	def exit_if_already_started():
		from commands import getstatusoutput
開發者ID:4pr0n,項目名稱:rip3,代碼行數:33,代碼來源:RipManager.py


注:本文中的ImageUtils.ImageUtils.create_thumbnail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。