@PutMapping(value = "/{modelId}") @ResponseStatus(value = HttpStatus.OK) @Authorize(action = Permission.ACTION_UPDATE) public void saveModel(@PathVariable String modelId, @RequestParam Map<String, String> values) throws TranscoderException, IOException { Model model = repositoryService.getModel(modelId); JSONObject modelJson = JSON.parseObject(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.get("name")); modelJson.put(MODEL_DESCRIPTION, values.get("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.get("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); }
try (FileReader in = new FileReader(svgPath); OutputStream out = new FileOutputStream(pngPath)) { PNGTranscoder transcoder = new PNGTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, w); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, h); transcoder.transcode(new TranscoderInput(in), new TranscoderOutput(out));
@Override public BufferedImage createImage(int width, int height) { return image[0] = super.createImage(width, height); } };
/** * Returns a transcoder object of the result image type. * * @return Transcoder object or <code>null</code> if there isn't a proper transcoder. */ protected Transcoder getTranscoder(){ switch(code) { case PNG_CODE: return new PNGTranscoder(); case JPEG_CODE: return new JPEGTranscoder(); case TIFF_CODE: return new TIFFTranscoder(); case PDF_CODE: try { Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder"); return (Transcoder)pdfClass.newInstance(); } catch(Exception e) { return null; } default: return null; } }
/** * Transcode file to PNG. * * @param file Output filename * @param width Width * @param height Height * @throws IOException On write errors * @throws TranscoderException On input/parsing errors. */ public void saveAsPNG(File file, int width, int height) throws IOException, TranscoderException { PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width)); t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height)); transcode(file, t); }
@VisibleForTesting PNGTranscoder createPngTranscoder() { return new PNGTranscoder(); }
/** * Transcodes the specified Document as an image in the specified output. * * @param document the document to transcode * @param uri the uri of the document or null if any * @param output the ouput where to transcode * @exception TranscoderException if an error occured while transcoding */ protected void transcode(Document document, String uri, TranscoderOutput output) throws TranscoderException { SVGRenderingAccuracyTest.this.manipulateSVGDocument(document); super.transcode(document, uri, output); } }
/** * Returns the image that represents the SVG document as a JPEG. * * @param outputStream The stream to use. */ public void createJPEG(OutputStream outputStream) throws TranscoderException { // Create a JPEG transcoder JPEGTranscoder t = new JPEGTranscoder(); // Set the transcoding hints. t.setTranscodingHints((Map)hints); // Set up the output stream TranscoderOutput output = new TranscoderOutput(outputStream); // Save the image. t.transcode(input, output); }
protected void transcode(Document document, String uri, TranscoderOutput output) throws TranscoderException { super.transcode(document, uri, output); this.doc = document; }
t.setTranscodingHints(transcoderHints); t.transcode(input, null); } catch (Exception e) { throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
private PNGTranscoder newPNGTranscoder(final Avatar.Size size) { final PNGTranscoder transcoder = createPngTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) size.getPixels()); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) size.getPixels()); return transcoder; } }
/** * Returns the <code>ImageTranscoder</code> the Test should * use */ public ImageTranscoder getTestImageTranscoder(){ ImageTranscoder t = super.getTestImageTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_MEDIA, parameter); return t; }
@Override protected void setImageSize(float width, float height) { if (width > 0 && height > 0) { super.setImageSize(width, height); } }
/** * Returns a transcoder object of the result image type. * * @return Transcoder object or <code>null</code> if there isn't a proper transcoder. */ protected Transcoder getTranscoder(){ switch(code) { case PNG_CODE: return new PNGTranscoder(); case JPEG_CODE: return new JPEGTranscoder(); case TIFF_CODE: return new TIFFTranscoder(); case PDF_CODE: try { Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder"); return (Transcoder)pdfClass.getDeclaredConstructor().newInstance(); } catch(Exception e) { return null; } default: return null; } }
TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result);
/** * Transcode file to PNG. * * @param file Output filename * @param width Width * @param height Height * @throws IOException On write errors * @throws TranscoderException On input/parsing errors. */ public void saveAsPNG(File file, int width, int height) throws IOException, TranscoderException { PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width)); t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height)); transcode(file, t); }
public void transcode ( Document inputDoc ) throws Exception { super.transcode(inputDoc,null,null); }
/** * Returns the <code>ImageTranscoder</code> the Test should * use */ public ImageTranscoder getTestImageTranscoder(){ ImageTranscoder t = super.getTestImageTranscoder(); t.addTranscodingHint(PNGTranscoder.KEY_ALTERNATE_STYLESHEET, parameter); return t; }
/** * Returns a transcoder object of the result image type. * * @return Transcoder object or <code>null</code> if there isn't a proper transcoder. */ protected Transcoder getTranscoder(){ switch(code) { case PNG_CODE: return new PNGTranscoder(); case JPEG_CODE: return new JPEGTranscoder(); case TIFF_CODE: return new TIFFTranscoder(); case PDF_CODE: try { Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder"); return (Transcoder)pdfClass.getDeclaredConstructor().newInstance(); } catch(Exception e) { return null; } default: return null; } }
private static ByteArrayOutputStream saveAsBytes(ImageTranscoder t, Document doc) throws Exception { TranscoderInput input = new TranscoderInput(doc); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outputStream); t.transcode(input, output); outputStream.flush(); return outputStream; }