AnsweredAssumed Answered

JPEG Image Resizing and creating a Thumbnail

Question asked by amitkumar75 on Apr 17, 2017
Latest reply on May 16, 2017 by amitkumar75

Hi friend,

 

I am very new to alfresco and i am required to write an api to JPEG to PNG and JPEG to JPEG.

My requirements are as below,

1. take a JPEG image from a folder in alfresco
2. convert it to PNG type and  resize it to different sizes and create thumbnails

3. resize the original JPEG image in folder  to different sizes and create thumbnail of small and big size.

 

I am using alfresco SDK 2.2.0

I dont know the correct approach and i need to do it within 2 days,

I am trying like below : 

currently i have only one image in articles folder in company home

=================================================================================

I have made changes in alfresco-global.properties.

 

ooo.exe=C:/ALFRES~1/LIBREO~1/App/libreoffice/program/soffice.exe
ooo.enabled=false
ooo.port=8100
img.root=C:\\alfresco-one\\imagemagick
img.coders=${img.root}\\modules\\coders
img.config=${img.root}
img.gslib=${img.root}\\lib
img.exe=${img.root}\\convert.exe

==================================================================================

 

 

 

ArticleImageTransformation.java
==================================================================================

// Getting the target image
NodeRef arNode = myAlfUtil.getNodeRefByFolderNameInCompanyHome("articles");
FileInfo arFileInfo = fileFolderService.getFileInfo(arNode);
FileInfo targetImage = null;
for(FileInfo image : fileFolderService.listFiles(hmNode)) {
targetImage = image;
}

//

 

ContentReader imageReader = serviceRegistry.getContentService().getReader(targetImage.getNodeRef(), ContentModel.PROP_CONTENT);
ContentWriter imageWriter = serviceRegistry.getContentService().getWriter(targetImage.getNodeRef(), ContentModel.PROP_CONTENT, true);
ImageTransformationOptions transformationOption = new ImageTransformationOptions();
//-geometry 137x171 -bordercolor "white" -border 1x1 -bordercolor "rgb(0,0,51)" -border 1x1
//transformationOption.setCommandOptions("-geometry 50x40 -bordercolor white -border 1x1 -border 1x1");
transformationOption.setCommandOptions("-resize 50%");
ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
imageResizeOptions.setMaintainAspectRatio(true);
imageResizeOptions.setHeight(100);
imageResizeOptions.setWidth(80);
transformationOption.setResizeOptions(imageResizeOptions);
transformationOption.setSourceNodeRef(targetImage.getNodeRef());
transformationOption.setTargetNodeRef(targetImage.getNodeRef());

ContentTransformer imageTransformer = serviceRegistry.getContentService().getTransformer(MimetypeMap.MIMETYPE_IMAGE_JPEG, MimetypeMap.MIMETYPE_IMAGE_JPEG, transformationOption);
imageTransformer.transform(imageReader, imageWriter);

 

 

=======================================================================================

 

But this is not working.
Any suggestion, help will be highly appreciated,
Please help me, it is like do or die problem for me.

Please forgive me for my English.

 

 

Regards,

Amit

Outcomes