去除/平滑gd库中的粗糙边缘(removing / smoothing rough edges in gd library)
我使用GD库来即时创建图像。
但是,当我旋转图像使用imagerotate()函数
它工作正常,但它给图像非常恼人的粗糙边缘
这是旋转。
如图所示。
那么如何让这些旋转图像的边/边平滑呢?I m using GD library to create images on the fly.
But when i rotate image using imagerotate() function
it works fine but it gives very much irritating rough edges of image
which is rotated.
as it is shown in this picture.
So how to make these sides/edges of rotated image smooth ?
原文:https://stackoverflow.com/questions/11925909
更新时间:2022-11-08 09:11
最满意答案
我想到了! 这是我更新的代码,以防其他人有类似的问题。
for image in soup.findAll("img"): print "Old Image Path: %(src)s" % image #Get file name filename = image["src"].split("/")[-1] #Get full path name if url has to be parsed parsedURL[2] = image["src"] image["src"] = '%s\%s' % (phonepath,filename) #Old File path (local to computer) #image["src"] = '%s\%s' % (out,filename) print 'New Path: %s' % image["src"] # print image outpath = os.path.join(out, filename) #retrieve images if parsedURL[2].lower().startswith("http"): #urlretrieve(image["src"], outpath) urlretrieve(parsedURL[2], outpath) print image["src"].lower() else: print "HTTP INFO " + urlparse.urlunparse(parsedURL) print "HTTP INFO " + image["src"].lower() urlretrieve(urlparse.urlunparse(parsedURL), outpath) #Constructs URL from tuple (parsedURL) #print image["src"].lower()
I figured it out! Here is my updated code in case anyone else has a similar issue.
for image in soup.findAll("img"): print "Old Image Path: %(src)s" % image #Get file name filename = image["src"].split("/")[-1] #Get full path name if url has to be parsed parsedURL[2] = image["src"] image["src"] = '%s\%s' % (phonepath,filename) #Old File path (local to computer) #image["src"] = '%s\%s' % (out,filename) print 'New Path: %s' % image["src"] # print image outpath = os.path.join(out, filename) #retrieve images if parsedURL[2].lower().startswith("http"): #urlretrieve(image["src"], outpath) urlretrieve(parsedURL[2], outpath) print image["src"].lower() else: print "HTTP INFO " + urlparse.urlunparse(parsedURL) print "HTTP INFO " + image["src"].lower() urlretrieve(urlparse.urlunparse(parsedURL), outpath) #Constructs URL from tuple (parsedURL) #print image["src"].lower()
相关问答
更多-
美丽的汤错误(Beautiful Soup error)[2022-01-05]
正如maozet所说,你的问题是标题是None,你可以检查该值以避免这样的问题: soup = BeautifulSoup(html) if soup.title != None: print soup.title # 'Google ' print soup.title.renderContents() # 'Google' f.writelines(domain) f.writelines(" ") f.writelines(sou ... -
脚本应该被执行为 - python spider2.py 代替 - ./spider2.py Script should be executed as - python spider2.py instead of - ./spider2.py
-
我可以通过指定用户代理标头来实现此功能。 我觉得它与https vs http有关,但我担心我不完全确定原因是什么。 import urllib2 from bs4 import BeautifulSoup site= "https://stackoverflow.com" hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safa ...
-
使用Selenium,Python中的Beautiful Soup刮掉灯箱覆盖层(Scrape a lightbox overlay using Selenium, Beautiful Soup in Python)[2024-02-01]
你根本不需要BeautifulSoup 。 Selenium本身在定位元素方面非常强大。 以下是迭代所有部门的工作代码,单击每个部门,提取课程列表并关闭覆盖窗口。 结果收集到字典中: from pprint import pprint from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from s ... -
我想到了! 这是我更新的代码,以防其他人有类似的问题。 for image in soup.findAll("img"): print "Old Image Path: %(src)s" % image #Get file name filename = image["src"].split("/")[-1] #Get full path name if url has to be parsed parsedURL[2] = i ...
-
正如我建议你应该写一个单独的python脚本。 我是这样做的: beautifulsoup.py文件内容: # -*- coding: utf-8 -*- import sys import os from bs4 import BeautifulSoup import codecs if sys.stdout.encoding is None: os.putenv("PYTHONIOENCODING", 'UTF-8') os.execv(sys.executable, ['pytho ...
-
美丽的汤什么也没有(Beautiful soup returns nothing)[2023-07-31]
background不是div标签的属性。 div标签的属性是: {'xmlns': '', 'style': 'box-sizing: border-box; width: 100%; margin: 0 0 10px 0; padding: 5px 10px; background: #fdc431; font-weight: bold; font-size: 14px; line-height: 20px; color: #fff;'} 所以,要么你必须使用 soup.find_all('div', ... -
美丽的汤不进口(Beautiful Soup not importing)[2022-10-19]
在Python 3中,print语句应该有括号print(soup.prettify()) ,我不知道为什么它不在你的情况下,似乎你有来自python 2版本的bs4 。 尝试再次强制安装漂亮的汤$ pip install --ignore-installed beautifulsoup4 。 In Python 3 that print statement should have parentheses print(soup.prettify()), I am not sure why it is not ... -
那“一堆python脚本”被称为python包 ; 那里应该有一个__init__.py文件。 它们一起形成一个连贯的整体,一组命名空间模块。 你可以从bs4包中导入BeautifulSoup类: from bs4 import BeautifulSoup 有关详细信息,请参阅文档 。 That 'bunch of python scripts' is called a python package; there should be a __init__.py file in there somewher ...
-
尝试使用不同的解析器。 您没有指定一个,所以您可能正在使用默认的html.parser 。 尝试使用lxml或html5lib 。 欲了解更多信息: http : //www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-a-parser Try using different parsers. You are not specifying one, so you are probably using the default html.parse ...