[resolved] change picture size

One Star

[resolved] change picture size

I've got a scenario like this:
First scan a list of files specifically all pictures(files with .jpg or jpeg) inside one folder;
then get the size of of the picture;
if the size is greater than a certain size make it smaller; if it's already smaller than that size just continue the process;
I'd like to ask if there's a way to re-size the picture. How to design this process? Could anyone give me some idea?
Thanks!

Accepted Solutions
One Star

Re: [resolved] change picture size

I finally find the solution (took a long time, ImageMagick is quite strange). It seems that in order to use ImageMagick you have to use the .exe and not use it like a .bat file. So the solution:
In your home directory: "C:\\Program Files\\ImageMagick-6.7.3-Q16"
in your tsystem, copy EXACTLY this:
"C:\\Program Files\\ImageMagick-6.7.3-Q16\\convert.exe "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) +" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
The copy of your images will be generated in the same folder of the previous images, if you want to generate them in an other folder, replace ((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY")) by an other directory path
The copy fo your images will have the prefix exact, of course it's up to you to change it.
Please tell me if you have achieved it. I've made the job, it works fine.

PS: don't forget that you have to put "\\" instead of "\" when you directly write a path

All Replies
Community Manager

Re: [resolved] change picture size

Hi
I see there is a component called JavaPictureResize on Talend exchange shared by kchalane, it could be used to re-size the pictures, I did not test this component yet, hope that it is the suitable component you are looking for.
The job design looks like:
tFileList--iterate---tFileProperties---main--tJavaRow--runIf_1---JavaPictureResize
--runIf_2---continue the process
on tJavaRow:
if(input_row.size>a certain size){
globalMap.put("isgreater",true);
}else{
globalMap.put("isgreater",false);
}
set the condition of runif_1 as:
(Boolean)globalMap.get("isgreater")
set the condition of runIf_2 as:
!(Boolean)globalMap.get("isgreater")

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] change picture size

Really appreciate your quick response. I download and installed that component.
Unfortunately, it's not allowed to connect tJavaRow to tJavapicturesize component using Runif, only row(main).
Then I tried to wrap that component into another subjob (using tRunJob). But tJavapicturesize needs input links. Is there another way to work it out?
Also that customized component is developed on tJavaRow. It seems that most code are still customized, including the parameter for the pics dimension. I really have trouble using it. I'm not good at coding thing. Any suggestion about this component?
Thanks!
Community Manager

Re: [resolved] change picture size

Hi
If the component need input links, you can use a tFixedFlowInput component to generate a row with fixed value. For example:
tFileList--iterate---tFileProperties---main--tJavaRow--runIf_1--tFixedFlowInput--main-->JavaPictureResize
--runIf_2---continue the process
I did not test this component yet, I only give you the hints and the job design, so I hope you will success in using it and share the experience with us or you know other way to re-size the picture.Smiley Wink
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] change picture size

Hi,
There is also ImageMagick that you can use with commandline, maybe it can help you.
Community Manager

Re: [resolved] change picture size

Hi,
There is also ImageMagick that you can use with commandline, maybe it can help you.

Good, if ImageMagick can be used with commandline way, we can use tSystem component to call ImageMagick command in Talend job.
elvalin1559, please try ImageMagick?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] change picture size

I'll give it a try. Thanks!
One Star

Re: [resolved] change picture size

Yes you have to install it, just go on the website and depending on your OS choose the right installer. Then for your job:

tFileList------tSystem
of cours you put the right directory inyour tFileList, and then for you tSystem:
"cd the_path_where_you_have_installed_imagemagick(for me C:\ImageMagick-6.7.3-Q16)" //carefull with "\", depending on the OS where the job is running
"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64\! "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
It should create the converted images with the prefix "exact" in your folder. Let me now if it works. ps:I didn't check the convert method of imagmagick, i've used yours
One Star

Re: [resolved] change picture size

Thank you so much for your quick reply. I was just preparing to repost with my job design and ask some more question. But you've already replied so I just got that installed and tried your post.
Do I have to put something between the two command?
"cd C:\Program Files\ImageMagick-6.7.3-Q16"
"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64\! "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
when I was using it, got this error message
Error: Unresolved compilation problem:
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
then I put \n between them but still not correct. What might be the problem?
When I tried the "cd C:\Program Files\ImageMagick-6.7.3-Q16" in the cmd, it was working. I think it might be the two commands issue.
Thanks!
Community Manager

Re: [resolved] change picture size

Hi
Do I have to put something between the two command?

Check the option 'Use home directory' and browse the directory C:\Program Files\ImageMagick-6.7.3-Q16.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] change picture size

Yes you have to install it, just go on the website and depending on your OS choose the right installer. Then for your job:

tFileList------tSystem
of cours you put the right directory inyour tFileList, and then for you tSystem:
"cd the_path_where_you_have_installed_imagemagick(for me C:\ImageMagick-6.7.3-Q16)" //carefull with "\", depending on the OS where the job is running
"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64\! "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
It should create the converted images with the prefix "exact" in your folder. Let me now if it works. ps:I didn't check the convert method of imagmagick, i've used yours

Perhaps there's something wrong with the command "convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64\! "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
The job can be executed but with following error message.
connecting to socket on port 3477
connected
Invalid Parameter - -resize
disconnected

I wonder if some of the quotes are necessary or right. THANKS!!!
One Star

Re: [resolved] change picture size

Remove the "\" before the "!".
One Star

Re: [resolved] change picture size

It's still not right. This even returned more error and couldn't be executed at all.
I forgot to mention I've already changed the expression as follows. And that "Invalid" message was coming from this expression, not the one you corrected.
"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))

Do you have any clue? I've been keeping trying.
Thanks.
One Star

Re: [resolved] change picture size

What do you exactly put in your tSystem?
One Star

Re: [resolved] change picture size

shown in pic and the expression is

"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
One Star

Re: [resolved] change picture size

try
"convert "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
One Star

Re: [resolved] change picture size

Really sorry to bother again...It's weird. Still not working. Got the error message as the first pic. I've tried many different ones.
Another pic is the one I also tried. I made the file the same name. Then still got "Invalid Parameter - -resize". Is there anything wrong with the ImageMagick command?
Thanks!
One Star

Re: [resolved] change picture size

do you get smthing when you put "convert help" in the tsystem?
One Star

Re: [resolved] change picture size

Do you mean to put only "convert help" in the command line? I tried and got "Invalid drive specification." So does this mean that I didn't make the ImageMagick working right? I have to make some changes to home directory?
Also I tried to changed the "to console" to normal in the standard output as shown in the picture. Then it executed without any error. The problem is that I didn't see any change to my file.
I put the command like "convert"+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))+" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")). I think it will rename as the same name (cover the original one). But nothing has changed.
Thank you!!!
One Star

Re: [resolved] change picture size

I finally find the solution (took a long time, ImageMagick is quite strange). It seems that in order to use ImageMagick you have to use the .exe and not use it like a .bat file. So the solution:
In your home directory: "C:\\Program Files\\ImageMagick-6.7.3-Q16"
in your tsystem, copy EXACTLY this:
"C:\\Program Files\\ImageMagick-6.7.3-Q16\\convert.exe "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) +" -resize 64x64 "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
The copy of your images will be generated in the same folder of the previous images, if you want to generate them in an other folder, replace ((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY")) by an other directory path
The copy fo your images will have the prefix exact, of course it's up to you to change it.
Please tell me if you have achieved it. I've made the job, it works fine.

PS: don't forget that you have to put "\\" instead of "\" when you directly write a path
One Star

Re: [resolved] change picture size

Maybe you'll need to put 64x64! instead of 64x64 to have exactly the right dimension (according to the ImageMagick API), so it gives:
"C:\\Program Files\\ImageMagick-6.7.3-Q16\\convert.exe "+((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) +" -resize 64x64! "+((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))+"\\exact_"+((String)globalMap.get("tFileList_1_CURRENT_FILE"))+"."+((String)globalMap.get("tFileList_1_CURRENT_FILEEXTENSION"))
One Star

Re: [resolved] change picture size

So cool!!! I just tried and it worked successfully. Really Appreciate your time and effort!!!
So the most tricky part is that \\ should be used instead of "\" in the regular command line. And also the convert.exe should be added to the command part. Then I can add other components to meet other requirements. Hope it will work smoothly.
Thank you so much again!!!
One Star

Re: [resolved] change picture size

Nice, wanted to solve it ^^. Good luck for your job man, see you !
Community Manager

Re: [resolved] change picture size

Hi
elvalin1559, congratulation! It will be very helpful for the guys who want to change the picuture's size later!
Or3l, thanks for your solutions and effort.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] change picture size

Strange, I have the same problem and my solution was to remove simply the blank in the full pathname of convert.exe  (I take care with \\ )