resize of folder selecting specific files

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

resize of folder selecting specific files

Post by censura10 »

Hi, wow just want to say what a great resource.

I wonder if you can help

Hello,

We have a program which embeds files uploaded from tablets used by our trainers and creates a word document with the embeded files in it.
All has worked fine with no problems until recently when we started to upgrade our tablets used and started using new tablets which have 8mp camera not 5mp on the older tablet models.

The problem being the result bmp files the program creates from jpg files uploaded from the tablets increases the file size from 3mb per picture to 23mb per picture with resolutions being 3264x2448 and 1440x864 respectively. This is a problem

So what i am looking for is if this program/code can on upload of the evidence as a folder containing lots of different evidence files run through the files and identify all the jpg files over a certain memory size or resolution size (whichever is easier) and reduces the size of these files replacing the original files and then to allow the software to carry on and do its thing on the new resized images.

so


1- Folder of File gets Upload to our server from the trainers tablets
2- Your software reduces size of all jpg files for pictures taken to about 800x480 maintaining size ratios and not distorting pictures, my thought was to take whatever the biggest dimension is and reduce this to 800 and by working out the other dimension by dividing larger dimension by small dimension of original we get the original ratio so in case of 8mb 3264x2448 is 1.333 there reduced file would be 800x 600 but on 5mp camera it would be 800x480 (In the folder are other files audio, video and also jpg thumb nails we don't want the thunbnail pictures resizing or other files just the bigger jpg pictures– so maybe have logic to select on size over a value or file memory size so not to change thumb nail jpg’s these are small and typically a few KB in size)
3- Make sure the original files are replaced with new reduced size with aspect ratio maintained and file names etc maintained(critical)

I would like some simple way to set size for largest size ie set at 800 for now but would want you to have a parameter - reduction size - 800 which i can change as and when to test different sizes and see resultant output filesize when our other software converts to bmp file

Also a snipit of code or api to call your routine so we can add this to the current software and fire up your software as needed in the process - so for clarity you code does the job it is a independent routine that on inserting or calling the routine will run your code on a specific folder as specified by our current software.

Here is a link to a example folder that we would want to reduce all the jpg images that are not thumbnails

https://www.dropbox.com/sh/quqzhcefrywe ... WGkIa?dl=0

the above is from a tablet using 8mp camera

https://www.dropbox.com/s/viyu3mtzwy10n ... 6.zip?dl=0

the above is from a tablet using a 5mp camera so you can see difference on jpg images we want as specified all images to be resize to 800 for largest dimension and other dimension resized in line with the aspect ratio of the origional image it is resizing from. Thus all images irrespective of what tablet is used have the same sized (800) image for the largest dimension.

To summerise :
Our Trainers hit upload button on their tablets and vis sftp a zipped folder is sent to a folder 'upload' on our windows 2012 server.

What i would like is for on detection of a new zipped folder uploaded to the upload folder from our trainers tablets for the magik code to resise all the jpg files that are not thumbnails to 800 (from largest dimension on origional file) and maintain the aspect ratio for other dimension and critically retaining file name and then our other software to start. Can this be done

Our server is windows server2012 R2



Thank you
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize of folder selecting specific files

Post by snibgo »

What version IM do you use? I'll assume v6.

What script language? I'll assume Windows BAT.

The IM operation is very simple, simply a resize. But you need to ensure that images are not processed multiple times, because each read/write of a jpeg may degrade it, even if no resizing is done.

So your script could be something like:

Code: Select all

for %%F in (*.jpg) do (

  for /F "usebackq" %%L in (`convert ^
    %%F -format "IsBig=%%[fx:w>800||h>800h?1:0]" info:`) do set %%L

  echo  %%F !IsBig!

  if !IsBig!==1 convert %%F -resize 800x800 %%F
)
This processes all the *.jpg files. For each one, it sets IsBig to "1" if either dimension is more than 800; otherwise "0". If IsBig is 1, it resizes to fit within a 800x800 box.

It could be written more concisely.
snibgo's IM pages: im.snibgo.com
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Thank you will this retain the aspect ratio for example on the 8mp the ratio is 1.66666 on 5mp camera 1.3333, also the files from 8 and 5mp council differ in so far on 5mp the frist dimension is bigger ie 1440x846 and 8mp the bigger dimension is quoted 2nd ie 3264x2448 .

as far degeigation would we be better resizing on the .bmp images instead.

Thanks for your help
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize of folder selecting specific files

Post by snibgo »

Yes, this retains aspect ratios.

3264x2448 becomes 800x600.

1440x864 becomes 800x480.
censura10 wrote:as far degeigation would we be better resizing on the .bmp images instead.
For image processing, never use JPEG unless you have to. JPEG uses lossy compression. It changes your images. Never use JPEG sources if you have anything better, and never write JPEG outputs unless you need to.
snibgo's IM pages: im.snibgo.com
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Hi thank you, we are using windows server 2012 R2 and have not installed IM yet
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Hi thank you, we are using windows server 2012 R2 and have not installed IM yet. So just to clarify if we insert the code you kindly wrote at the beginning of our software will it run or do we call it/ or anything or will it just run as it is. Is IM running in the background and so do we always need to make sure this the case.
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Hi thank you, we are using windows server 2012 R2 and have not installed IM yet. So just to clarify if we insert the code you kindly wrote at the beginning of our software will it run or do we call it/ or anything or will it just run as it is. Is IM running in the background and so do we always need to make sure this the case.

sorry if this sounds really basic but never used this software before
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize of folder selecting specific files

Post by snibgo »

censura10 wrote:So just to clarify if we insert the code you kindly wrote at the beginning of our software will it run or do we call it/ or anything or will it just run as it is.
I don't know what your software is, so I can't answer that question. The code I showed would need to be part of a BAT script, or modified for another script or compiled language.
censura10 wrote:Is IM running in the background and so do we always need to make sure this the case.
No, IM does not run in the background. "convert.exe" is an IM v6 program that you run when you want. For IM v7, the program is "magick.exe".
snibgo's IM pages: im.snibgo.com
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

which version is best for my needs for winserver 2012 r2
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize of folder selecting specific files

Post by snibgo »

For v6 installation see http://legacy.imagemagick.org/script/bi ... hp#windows

For v7 installation see http://www.imagemagick.org/script/binar ... hp#windows

I don't know what your needs are.
snibgo's IM pages: im.snibgo.com
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Hi sorry to be a pain

I have saved the code you kindly supplied as a file on my desktop called assessor.bat

I have installed v7 on my server

I want to run your script to test it the folder :- C:\Users\Administrator\Desktop\Petrisor_Toderita_Cskills L3 Carpentry_Grays station first visit_2017-04-20 103726_files

how would i do this
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resize of folder selecting specific files

Post by snibgo »

I'm sorry, I don't have the time to teach you how to run scripts.
snibgo's IM pages: im.snibgo.com
censura10
Posts: 8
Joined: 2017-04-28T23:10:30-07:00
Authentication code: 1151

Re: resize of folder selecting specific files

Post by censura10 »

Of course no worries , can you tell me how i can get your script to work on the folder- C:\Users\Administrator\Desktop\Petrisor_Toderita_Cskills L3 Carpentry_Grays station first visit_2017-04-20 103726_files

also as i am using v7 not 6 do i replace convert with magick


thank you
Post Reply