I am trying to use the Image component in CQ5.6 to include an SVG image on a page. I can get the component to use the SVG by dragging the image from the content finder to the component, but this also causes an error in the log:
Caused by: javax.imageio.IIOException: No decoder available to load the image
at com.day.image.Layer.<init>(Layer.java:786)
at com.day.image.Layer.<init>(Layer.java:588)
at com.day.image.Layer.<init>(Layer.java:511)
at com.day.cq.commons.ImageHelper.createLayer(ImageHelper.java:173)
at com.day.cq.commons.ImageResource.getLayer(ImageResource.java:569)
at libs.foundation.components.parbase.img_GET.writeLayer(img_GET.java:72)
at com.day.cq.wcm.commons.AbstractImageServlet.doGet(AbstractImageServlet.java:80)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
at org.apache.sling.scripting.java.impl.ServletWrapper.service(ServletWrapper.java:126)
at org.apache.sling.scripting.java.impl.JavaScriptEngineFactory.callServlet(JavaScriptEngineFactory.java:211)
... 88 more
I've made several attempts to add support for SVGs by including SVG implementations of the javax.imageio, but have yet to succeed. The closest that I have come to success was using Batik, in which case CQ5 seemed to get stuck in an infinite loop at Layer.java:769-781.
Has anybody managed to make the OOTB Image component work with SVG images?
I ran into the same problem. I tried to download the file manually from CRX and opening that in my default image viewer. Unfortunately, my default image viewer also gave the same error.
For me the problem was with uploading part of that image. My InputStream passed in JCRUtil.put skipped some bytes to write because I used TikaInputStream before writting for validating the mediaType of the uploaded file.
Related
I developed a Java PDF viewer using Apache PDFBox. The problem is, when rendering a page of a PDF, if the page has file attachments, there is no icon shown in PDFBox rendering, like there is a paper clip icon, when such a file is opened in Adobe PDF reader.
Is it possible to automatically have such icons in the rendering using PDFBox? I think I saw such a code some time ago, like a single line that switches this behavior on and off but I can't find it. Thanks.
This was fixed in PDFBOX-5394 and will be in the version 2.0.26. However only one single symbol will be shown at this time: a paperclip in fixed size.
When using PDFBox, we encounter an issue where if we call render on a PDDocument, it sometimes loses content, such as fonts or certain shapes.
Having dug into this, it looks to be caused by the use of SoftReference throughout the PDFBox code base. The JVM seems to reap the underlying contents of the PDDocument while it's attempting to render the image. As a result, we see org.apache.pdfbox.cos.COSDocument - Warning: You did not close a PDF Document at random intervals.
Has anyone else encountered this issue? If so, how was it solved?
So far, our solution has been to write the contents to a file, then read and render.
I had a similar issue. The PDF contained an image which was not rendered. The result was just a plain white BufferedImage.
Including the JBIG2 library (see https://pdfbox.apache.org/2.0/dependencies.html) to my classpath and updating the PDFBox-version from 2.0.15 to 2.0.26 solved the issue for me.
I'm trying to download some images from a website. I've been using Jsoup to do some scraping and have successfully downloaded images given a url before but the images on this website are in svg format. There is no link to a location where the svg file is located, the image is embedded in svg tags. I have seen Batik used for converting svg files to other image formats but I don't have the svg file available.
Is there any way to do this? Would appreciate any guidance. Thank you.
Typically an SVG image is not a file, but rather it is included in the response body of the GET request from a browser. What you can do to test this is to download a REST client, POSTMAN if you're using Chrome, and issue a GET request to the url of the svg. The response will be the SVG image. Thinking now in terms of Java, you may have to do some parsing in your code to grab just the actual svg element because the website may return extra junk wrapping the embedded svg.
I have used Batik and I think it's not a good solution for many reasons for what you're trying to do. In the past I ended up writing Java code that executed a 3rd party program for image conversion. It was basically a Command class that wrapped the execution of phantomjs. Download phantomjs, and use the rasterize.js file in the examples folder to achieve quick and easy image conversion from .svg to .png or .jpg. At the command line, the command for phantomjs is something like:
phantomjs rasterize.js C:\sourceImage.svg C:\outputImage.png
If you are doing image manipulation, I did it a lot using ImageMagick as phantomjs is only good for rendering svg to a rasterized image format.
In your case what you want to do is for every svg image at the url, GET the svg, parse it into a String, write that String to a file, then do something like:
String command = "C:\\phantomjs\\phantomjs.exe C:\\phantomjs\\rasterize.js C:\\source.svg C:\\output.png"
Process process = Runtime.getRuntime().exec(command);
Obviously make your code more general, replacing the values in the command string with resusable variables.
If this is in the context of a commercial platform, you can install phantomjs and your java app on a single server, and then just connect this app via REST endpoints to your svg finder app that gets the images. When your svg finder app gets an image, have it parse it, format it, then POST it to the phantomjs server for rendering and uploading/storage.
Just save the part of the HTML file between the <svg> tags (including the <svg>). Give it a .svg extension. You should then be able to open it in a browser, or pass it to Batik, ImageMagick or some other converter.
I would like to get a GIF image from the network, but I found that if I download the whole GIF image, it would cause a lot of network traffic.
Can I get only the first frame of a GIF image without downloading all the other frames?
9 years 6 months later, the perfect time to help out.
This can be accomplished using ImageMagick using the command:
magick mogrify -format png *.gif[0]
using a console in the directory of the folder containing the file(s).
Well, I haven't found ready-to-use solution, but you can do this way (it'll lead to some "low-level" tricks):
Following wiki about GIFs, animated gif files can be splitted into frames, and end of frame can be easily recognized. So, you'll need to read GIF header, screen information, information about animation into buffer, download first frame and append information like GIF is ended ("3B" following wiki article). And, if you copy this data into separate bufer, you'll be able to continue whole file downloading without re-downloading first frame.
Also you can edit header information to format first frame into static gif.
I am using applet viewer for my Web Application.
Before loading the applet viewer, is it possible to remove the java loading image.
Please check the attachment.
Thanks -
Haan
See the image parameter in Special Attributes of Applets. To 'remove' the image you might simply replace it with a 1x1 transparent GIF, but a more meaningful loading image would be best.