public void transform()

in src/main/java/org/apache/sling/thumbnails/internal/TransformerImpl.java [101:137]


    public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out)
            throws IOException {
        if (!thumbnailSupport.getSupportedTypes().contains(resource.getResourceType())) {
            throw new BadRequestException("Unsupported resource type: " + resource.getResourceType());
        }
        ThumbnailProvider provider = getThumbnailProvider(resource);
        log.debug("Using thumbnail provider {} for resource {}", provider, resource);
        try (InputStream thumbnailIs = provider.getThumbnail(resource)) {

            InputStream inputStream = thumbnailIs;
            for (TransformationHandlerConfig config : transformation.getHandlers()) {
                log.debug("Handling command: {}", config);

                TransformationHandler handler = getTransformationHandler(config.getHandlerType());
                if (handler != null) {
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(),
                            config.getHandlerType());
                    handler.handle(inputStream, outputStream, config);
                    inputStream = new ByteArrayInputStream(outputStream.toByteArray());
                } else {
                    log.info("No handler found for: {}", config.getHandlerType());
                }
            }
            if (!getMetaType(resource).equals(format.getMimeType())) {
                log.debug("Converting to {}", format);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Builder<? extends InputStream> builder = Thumbnails.of(inputStream);
                builder.outputFormat(format.toString());
                builder.scale(1.0);
                builder.toOutputStream(baos);
                inputStream = new ByteArrayInputStream(baos.toByteArray());
            }

            IOUtils.copy(inputStream, out);
        }
    }