当前位置: 首页>>代码示例>>Python>>正文


Python ImageUtils.get_dimensions方法代码示例

本文整理汇总了Python中ImageUtils.ImageUtils.get_dimensions方法的典型用法代码示例。如果您正苦于以下问题:Python ImageUtils.get_dimensions方法的具体用法?Python ImageUtils.get_dimensions怎么用?Python ImageUtils.get_dimensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageUtils.ImageUtils的用法示例。


在下文中一共展示了ImageUtils.get_dimensions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_existing_image

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [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: start

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [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

示例3: copy2

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [as 别名]
		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')

		(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
开发者ID:PlopFriction,项目名称:gonewilder,代码行数:33,代码来源:DB.py

示例4: str

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [as 别名]
            print "THREAD: %s: failed to download %s to %s: %s\n%s" % (
                url["path"],
                url["url"],
                saveas,
                str(e),
                str(format_exc()),
            )
            result["error"] = "failed to download %s to %s: %s\n%s" % (url["url"], saveas, str(e), str(format_exc()))
            self.results.append(result)
            self.current_threads.pop()
            return

            # Save image info
        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(),
            )
开发者ID:jadedgnome,项目名称:rip3,代码行数:33,代码来源:RipManager.py

示例5: Exception

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [as 别名]
				}
				ImageUtils.httpy.download(media, saveas, headers=headers)
				if path.getsize(saveas) == 503:
					raise Exception('503b = removed')
			except Exception, e:
				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, thumbsaveas)
			if media_type == 'audio':
				# Audio files don't have width/height/thumbnail
				width = height = 0
				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)))
开发者ID:4pr0n,项目名称:gonewilder,代码行数:33,代码来源:Gonewild.py

示例6: add_existing_image

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [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

示例7: str

# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import get_dimensions [as 别名]
		result['image_name'] = path.basename(saveas)
		# Attempt to dowload image at URL
		try:
			self.httpy.download(url['url'], saveas)
		except Exception, e:
			print 'THREAD: %s: failed to download %s to %s: %s\n%s' % (url['path'], url['url'], saveas, str(e), str(format_exc()))
			result['error'] = 'failed to download %s to %s: %s\n%s' % (url['url'], saveas, str(e), str(format_exc()))
			self.to_remove.append( (url['album_id'], url['i_index'] ) )
			self.results.append(result)
			self.current_threads.pop()
			return

		# Save image info
		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
开发者ID:4pr0n,项目名称:rip3,代码行数:33,代码来源:RipManager.py


注:本文中的ImageUtils.ImageUtils.get_dimensions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。