[PYTHON] Until you edit an SVG file with AutoCAD to PNG.

SVG > DXF I wanted to edit a small SVG file in AutoCAD and finally make it a PNG, but AutoCAD couldn't read the SVG directly.

I searched and found a lot of conversion sites, but neither DWG nor DXF could be opened in AutoCAD on the first site I tried.

When I regained my mind and converted it on the next site, I was able to open it brilliantly. Convert SVG to DXF Online Free-Convert SVG DXF

AutoCAD> PNG (No)

After editing with AutoCAD, I wanted to output as PNG, but the PNG image exported with the PNGOUT command as shown on the next page is not at a very practical level and is too rough to be used for thumbnails and icons. It was. PNGOUT[PNG export](command) | AutoCAD 2016 | Autodesk Knowledge Network

AutoCAD > PDF As for the print quality, I have no complaints about it, so it was perfect if I output it as printed matter instead of writing it to a file.

There were five preset PDF plotter preferences, but I didn't hesitate to choose the third ʻAutoCAD PDF (High Quality Print) .pc3`. (I haven't tried anything else.)

DWG to PDF.pc3
A generic driver used in AutoCAD 2015 and earlier.
AutoCAD PDF (General Documentation).pc3
A general-purpose driver suitable for most applications.
AutoCAD PDF (High Quality Print).pc3
Generates a PDF file optimized for printing on paper.
AutoCAD PDF (Smallest File).pc3
Generates a PDF with the smallest possible file size.
AutoCAD PDF (Web and Mobile).pc3
Generates a PDF file that supports hyperlinks on mobile devices and web browsers.

PDF > PNG I searched for this too and found a lot of sites, so I tried it on the top site and it worked. PDF PNG Converter-Online PDF to PNG

Make the background transparent.

I used Python's PIL to make the background transparent.

#This is the only import
from PIL import Image

#Open image
im = Image.open("hoge.png ")

#Convert to 8bit grayscale mode.
L = im.convert("L")

#Invert the black and white of the L channel,
A = L.point(lambda x: 255 if x < 128 else 0)

#Combine as alpha channel A.
im = Image.merge("LA",(L,A))

#Save the image.
im.save("hoge2.png ")                         

The above is a memo to edit the SVG file to PNG.

Only Python can convert SVG files to PNG, but I think that a certain environment is required after editing SVG.

This time, due to the SSD failure, the OS was rebuilt, so I had to work at the company or at hand, but thanks to the conversion site, it was very helpful.

Recommended Posts

Until you edit an SVG file with AutoCAD to PNG.
Convert svg file to png / ico with Python
[Python Kivy] How to create an exe file with pyinstaller
How to read an Excel file (.xlsx) with Pandas [Python]
When you want to send an object with requests using flask
Until you start Jupyter with Docker
[Python] Write to csv file with Python
Output to csv file with Python
Create an Excel file with Python3
Output cell to file with Colaboratory
Until you run python with apache
Until you shake ruby with renpy
[Introduction to machine learning] Until you run the sample code with chainer
What to do if you couldn't send an email to Yahoo with Python.
What to do if you get lost in file reference with FileNotFoundError
Note until you use emacs with WSL
How to convert Python to an exe file
Convert psd file to png in Python
Quickly create an excel file with Python #python
Until you confirm iOS communication with mitmproxy
Convert PDF files to PNG files with GIMP
Convert HEIC files to PNG files with Python
Until you can use opencv with python
Try to generate an image with aliasing
Create an upgradeable msi file with cx_Freeze
Workaround if you get an error when trying to install PySide with pip
I want to write an element to a file with numpy and check it.
What to do if you get an error when installing python with pyenv