Sponsored Content
Top Forums Shell Programming and Scripting Simple script for resize, crop and optimize jpg Post 303025722 by danjde on Saturday 10th of November 2018 11:39:29 AM
Old 11-10-2018
Simple script for resize, crop and optimize jpg

Hi Friends,
I'm trying to create a script that allows me to recursively resize, crop (holding the center of the image) and optimize images jpg, jpeg, png for a specific folder and subfolder with the ability to exclude certain folder and its subdirectory.

Again, I should to do with this script:

1) exclude images under a certain KB size
2) exclude images previous a certain date
3) exclude images in specific folders or sub-folders
4) resize images to precise height (400px for example)
5) crop images (gravity center) transforming into the square image with each side by 400px
6) optimize the image compression ratio


Code:
for f in `find . -name "*.jpg"`
do
    convert $f -resize x400\> $f.resized.jpg
done


then crop (gravity center) and optimize the result images


Code:
for f in `find . -name "*.jpg"`
do
    convert $f -gravity center -crop 400x400+0+0 -quality 50% $f.resized.jpg
done

But still I don't know how exclude file for size or folder and eventually how to merge the whole in a single script
I'm not a scripting expert, so I ask you if you can help me.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

optimize the script

Hi, I have this following script below. Its searching a log file for 2 string and if found then write the strings to success.txt and If not found write strings to failed.txt . if one found and not other...then write found to success.txt and not found to failed.txt. I want to optimize this... (3 Replies)
Discussion started by: amitrajvarma
3 Replies

2. UNIX for Dummies Questions & Answers

Can we optimize this simple script ?

Hi All , I am just a new bie in Unix/Linux . With help of tips from 'here and there' , I just created a simple script to 1. declare one array and some global variables 2. read the schema names from user (user input) and want2proceed flag 3. if user want to proceed , keep reading user... (8 Replies)
Discussion started by: rajavu
8 Replies

3. UNIX for Dummies Questions & Answers

optimize shell script (snapshots)

I've a script to do some snapshots but the time it does so is very different... once i got a snapshot under 1 sec, on the other hand it took 3 sec, but nothing else changed, i didnt even move the cursor or something. I put the script on a ramdisk and its faster, but still swing from under 1... (1 Reply)
Discussion started by: mcW
1 Replies

4. Shell Programming and Scripting

Simple BASH shell script to rename webcam jpg and copy into a new directory.

System: Ubuntu Intrepid Ibex I'm running webcamd as a sort of "security" program, but I need a script that will archive my webcam.jpg files. So, take the following file: /home/slag/www/webcam.jpg Rename it--preferably with a time stamp. Place it in say: /home/slag/www/history/ ... (4 Replies)
Discussion started by: robfindlay
4 Replies

5. Shell Programming and Scripting

find jpg's mkdir script help

I am having a problem getting this to work right. The script needs to search through directories and subdirectories. If a jpg is found then create a folder in that directory, so on and so forth. Here is what I have so far but it doesn't work right. Help please #!/bin/bash for d in `find ./... (1 Reply)
Discussion started by: jedhypes
1 Replies

6. Shell Programming and Scripting

Optimize and Speedup the script

Hi All, There is a script (test.sh) which is taking more CPU usage. I am attaching the script in this thread. Could anybody please help me out to optimize the script in a better way. Thanks, Gobinath (6 Replies)
Discussion started by: ntgobinath
6 Replies

7. Emergency UNIX and Linux Support

Help to optimize script running time

Dear Forum experts I have the below script which I made to run under bash shell, it runs perfectly for low records number, let us say like 100000. when I put all records (3,000,000), it's takes hours can you please suggest anything to optimize or to run in different way :-| {OFS="|";... (6 Replies)
Discussion started by: yahyaaa
6 Replies

8. UNIX for Dummies Questions & Answers

optimize if block : shell script

Hi, I need a shell script to determine if a no. is either even, greater than 4, less than 8 SHELL : ksh OS : RHEL 6 this is the if block of the script mod=`expr $num % 2` if || || then echo "No. is either even or greater than 4 or less than 8" fi this code works... (2 Replies)
Discussion started by: sam05121988
2 Replies

9. Shell Programming and Scripting

Optimize my mv script

Hello, I'm wondering if there is a quicker way of doing this. Here is my mv script. d=/conversion/program/out cd $d ls $d > /home/tempuser/$$tmp while read line ; do a=`echo $line|cut -c1-5|sed "s/_//g"` b=`echo $line|cut -c16-21` if ;then mkdir... (13 Replies)
Discussion started by: whegra
13 Replies

10. Shell Programming and Scripting

Help Optimize the Script Further

Hi All, I have written a new script to check for DB space and size of dump log file before it can be imported into a Oracle DB. I'm relatively new to shell scripting. Please help me optimize this script further. (0 Replies)
Discussion started by: narayanv
0 Replies
PUZZLE-DIFF(1)															    PUZZLE-DIFF(1)

NAME
puzzle-diff - Compare pictures with libpuzzle SYNOPSIS
[-b <contrast barrier for cropping>] [-c] [-C <max cropping ratio>] [-e] [-E <similarity threshold>] [-h] [-H <max height>] [-l <lambdas>] [-n <noise cutoff>] [-p <p ratio>] [-t] [-W <max width>] <file 1> <file 2> DESCRIPTION
puzzle-diff compares two pictures and outputs the normalized distance. Try puzzle-diff -h for more info. EXAMPLES
Output distance between two images: $ puzzle-diff pic-a-0.jpg pics-a-1.jpg 0.102286 Compare two images, exit with 10 if they look the same, exit with 20 if they don't (may be useful for scripts): $ puzzle-diff -e pic-a-0.jpg pics-a-1.jpg $ echo $? 10 Compute distance, without cropping and with computing the average intensity of the whole blocks: $ puzzle-diff -p 1.0 -c pic-a-0.jpg pic-a-1.jpg 0.0523151 AUTHORS
Frank DENIS libpuzzle at pureftpd dot org SEE ALSO
libpuzzle(3), puzzle_set(3) 2012-05-09 PUZZLE-DIFF(1)
All times are GMT -4. The time now is 10:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy