如何增加图像的大小并保存图片

2024-10-04 03:20:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图可视化一组RDF海龟,并使用以下代码:

!pip install pydotplus
!pip install graphviz

import io
import pydotplus
from IPython.display import display, Image
from rdflib.tools.rdf2dot import rdf2dot

def visualize(g):
    stream = io.StringIO()
    rdf2dot(g, stream, opts = {display})
    dg = pydotplus.graph_from_dot_data(stream.getvalue())
    png = dg.create_png()
    display(Image(png))

visualize(g)

这里,g是我的rdfgraph

确实创建了一个图像,但它太小了,我不知道如何保存它。有人能帮我吗


Tags: installpipfromioimageimportstreampng
2条回答

可以使用opencv调整图像大小

import cv2

image=cv2.imread("Your image")
image=cv2.resize(image,("your expected x co-ordinate value","your expected y co-ordinate value"))
cv2.imwrite("location where you want to save",image)

范例

image=cv2.imread("myimage.jpeg")
image=cv2.resize(image,(700,700))
cv2.imwrite('/home/desktop/',image)
import io
import pydotplus
from IPython.display import display, Image
from rdflib.tools.rdf2dot import rdf2dot

def visualize(g):
    stream = io.StringIO()
    rdf2dot(g, stream, opts = {display})
    pydot_graph = pydotplus.graph_from_dot_data(stream.getvalue())
    pydot_graph.write_png('original_tree.png')
    pydot_graph.set_size('"5,5!"')
    pydot_graph.write_png('resized_tree.png')

All the attributes defined in the Graphviz dot language should be supported.

Attributes can be set through the dynamically generated methods:

set_[attribute name], i.e. set_size, set_fontname

单击图片以了解大小,因为它似乎无法在浏览器中正确显示

相关问题 更多 >