I have a SVG image on this path http://www.quickdesign.com/user-uploads/5555f546857ce-saved.svg
Which i need to convert into PNG for which i am using below code on this php file http://www.quickdesign.com/png.php
<?php
$svg_file_name = 'user-uploads/5555f546857ce-saved.svg';
$png_file_name = 'png/converted.png';
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$svg = file_get_contents($svg_file_name);
$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg;
$im->readImageBlob($svg);
/*png settings*/
$im->setImageFormat("png32");
$im->writeImage($png_file_name);
header('Content-type: image/png');
echo $im;
$im->clear();
$im->destroy();
?>
If i remove the line $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg; Then it gives fatal error Uncaught exception 'ImagickException' with message 'no decode delegate for this image format
Can anyone please help me how to convert above svg image to PNG image using PHP.
Any help would be appreciated.
Thanks
ImageMagick uses delegates to read some images. It looks like the delegate it is using for SVG files on your system is unable to the SVG file you are telling it to read.
Reading that file also fails on my system due to this bit:
<stop fill="url(#svg_14)" stop-color="#A0D9F7" offset="0"/>
with the error message:
php: unrecognized color `svg_14' # warning/color.c/GetColorCompliance/1046.
php: unable to open image `svg_14': No such file or directory # error/blob.c/OpenBlob/2674.
php: no decode delegate for this image format `' # error/constitute.c/ReadImage/501.
url support inside SVG files is a bit flaky. It seems that svg_14 is defined at the end of the file. Moving it to the start makes the file be 'readable' but the image looks different to how it should appear.
I would suggest finding out what delegate ImageMagick is using to decode SVG files, which may be found with convert -list configure and finding if there is a more recent version of that library which fixes the issue.
Related
I am trying to covert a pdf to html using Pandoc. I have installed pandoc binary , added the environment variable path and then using
import pypandoc
import os
os.environ.setdefault('PYPANDOC_PANDOC', 'C://Program Files//Pandoc//pandoc.exe')
file_path = r"D:/46580375_1593783098922.pdf"
output = pypandoc.convert_file("46580375_1593783098922.pdf", to='html', outputfile= 'test.html')
It is giving me an error :
RuntimeError: Invalid input format! Got "pdf" but expected one of
these: commonmark, creole, csv, docbook, docx, dokuwiki, epub, fb2,
gfm, haddock, html, ipynb, jats, jira, json, latex, man, markdown,
markdown_github, markdown_mmd, markdown_phpextra, markdown_strict,
mediawiki, muse, native, odt, opml, org, rst, t2t, textile, tikiwiki,
twiki, vimwiki
What am I missing?
As the error said, you can't convert PDF to HTML via pandoc.
I have a directory called "features" in the root and inside this directory has image "state_transitation.JPG" and document "myMdc_features.md"
I am trying to add an image "state_transitation.JPG" to the md extension document "myMdc_features.md" in my repository by using markdown below:
![alt text](./state_transitation.JPG)
![alt text](/state_transitation.JPG)
![alt text](state_transitation.JPG)
<p>
<img src="state_transitation.JPG" />
</p>
I tried all above options but this is giving page could not be found error. 404
Both myMdc_features.md and image file are in same path/directory.
What is the correct way to display an image in gitlab myMdc_features.md?
I think that the first option should work, assuming they are in the same folder. I made an example repostiory here that works.
Source of the file:
Hello World
![](./i-have-no-idea-what-im-doing.jpg)
Output in GitLab:
I took some images in my camera and tried to resize them using opencv library but i think that i can't read the images I don't know the reason why.Thank you for the help in advance.
I have a python 3.8 version and the updated opencv library version.Not much of a background I guess.
import os,cv2
count=0
for file in os.listdir('E:\Projects\Python\Resixing images\Images'):
if file.endswith('.jpg'):
print(file)
img=cv2.imread(file)
img2=img.copy()
img2=cv2.resize(img2,(700,700))
name="resize"+str(count)+".jpg"
cv2.imwrite(name,img2)
count+=1
I receive an error message
P_20191107_214848_SRES.jpg
Traceback (most recent call last):
File "E:\Projects\Python\Resixing images\image changing res.py", line 7, in
img2=img.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
[Finished in 9.7s]
Try this:
img=cv2.imread('E:\Projects\Python\Resixing images\Images' + '\' + file)
The problem was that you were sending only the name of the file to the python program, so the program tried to look for the image in the current directory and not at your specified path. The above change should fix the problem.
also, a good idea would be to have 2 // instead of 1 /, just to avoid any format specifier in the middle of things, or you could just use r to mention the path to be raw string
img=cv2.imread('E:\\Projects\\Python\\Resixing images\\Images' + '\\' + file)
img=cv2.imread(r'E:\Projects\Python\Resixing images\Images\' + file)
Trying to load a PDF from the local file system and getting a "not authorized" error.
"File "/env/local/lib/python3.7/site-packages/wand/image.py", line 4896, in read self.raise_exception() File "/env/local/lib/python3.7/site-packages/wand/resource.py", line 222, in raise_exception raise e wand.exceptions.PolicyError: not authorized `/tmp/tmp_iq12nws' # error/constitute.c/ReadImage/412
The PDF file is successfully saved to the local 'server' from GCS but won't be loaded by Wand. Loading images into OpenCV isn't an issue, just happening when trying to load PDFs using Wand/ImageMagick
Code to load the PDF from GCS to local file system into Wand/ImageMagick is below
_, temp_local_filename = tempfile.mkstemp()
gcs_blob = STORAGE_CLIENT.bucket('XXXX').get_blob(results["storedLocation"])
gcs_blob.download_to_filename(temp_local_filename)
# load the pdf into a set of images using imagemagick
with(Image(filename=temp_local_filename, resolution=200)) as source:
#run through pages and save images etc.
ImageMagick should be authorised to access files on the local filesystem so it should load the file without issue instead of this 'Not Authorised' error.
PDF reading by ImageMagick has been disabled because of a security vulnerability Ghostscript had. The issue is by design and a security mitigation from the ImageMagick team will exist until. ImageMagick Enables Ghostscript processing of PDFs again and Google Cloud Functions update to that new version of ImageMagick with PDF processing enabled again.
There's no fix for the ImageMagick/Wand issue in GCF that I could find but as a workaround for converting PDFs to images in Google Cloud Functions, you can use this [ghostscript wrapper][2] to directly request the PDF conversion to an image via Ghostscript and bypass ImageMagick/Wand. You can then load the PNGs into ImageMagick or OpenCV without issue.
requirements.txt
google-cloud-storage
ghostscript==0.6
main.py
# create a temp filename and save a local copy of pdf from GCS
_, temp_local_filename = tempfile.mkstemp()
gcs_blob = STORAGE_CLIENT.bucket('XXXX').get_blob(results["storedLocation"])
gcs_blob.download_to_filename(temp_local_filename)
# create a temp folder based on temp_local_filename
temp_local_dir = tempfile.mkdtemp()
# use ghostscript to export the pdf into pages as pngs in the temp dir
args = [
"pdf2png", # actual value doesn't matter
"-dSAFER",
"-sDEVICE=pngalpha",
"-o", temp_local_dir+"page-%03d.png",
"-r300", temp_local_filename
]
# the above arguments have to be bytes, encode them
encoding = locale.getpreferredencoding()
args = [a.encode(encoding) for a in args]
#run the request through ghostscript
ghostscript.Ghostscript(*args)
# read the files in the tmp dir and process the pngs individually
for png_file_loc in glob.glob(temp_local_dir+"*.png"):
# loop through the saved PNGs, load into OpenCV and do what you want
cv_image = cv2.imread(png_file_loc, cv2.IMREAD_UNCHANGED)
Hope this helps someone facing the same issue.
I am quite new to inkscape and I would like to process a batch of SVGs using the command line interface with the following command (in the same directory as the SVG):
$ inkscape -D -z NMY.svg
However, when I try to load an SVG with the CLI I get the following warning:
** (inkscape-bin:8875): WARNING **: Can't open file: NMY.svg (doesn't exist)
** (inkscape-bin:8875): WARNING **: Can't open file: NMY.svg (doesn't exist)
** (inkscape-bin:8875): WARNING **: Specified document NMY.svg cannot be opened (does not exist or not a valid SVG file)
However, opening the same SVG from the GUI properly displays the image.
Here is the header SVG in question in case there is something wrong with it:
<?xml version='1.0' encoding='iso-8859-1'?>
<svg version='1.1' baseProfile='full'
xmlns:svg='http://www.w3.org/2000/svg'
xmlns:rdkit='http://www.rdkit.org/xml'
xmlns:xlink='http://www.w3.org/1999/xlink'
xml:space='preserve'
width='250px' height='150px' >
I am using inkscape Inkscape 0.92.2 5c3e80d, 2017-08-06 on MacOS 10.14.
Thanks!
Found the problem, I had to specify the absolute path to the file.