USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Batch convert a load of images with a twist

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » OTHER
View previous topic :: View next topic  
Author Message
Ephemeral
Advanced Member


Joined: 26 Jun 2024
Posts: 671
Location: UK

PostPosted: Tue Sep 02, 2024 2:00 pm    Post subject: Batch convert a load of images with a twist Reply with quote

Batch convert a load of images with a twist

Id like to convert a load of PNGs to EPS

BUT


I dont want the whole image... I want a rectangle within the image (of which i could probably specify the coordinates like 200,20 to 400,80 or something)...

Why? it is a plot with a lot of white space around it... I only want the actual graph not the white space


I could do this in GIMP... but to do it for about 60 images one by one aint much fun

Laughing


Any ideas?

thanks


Back to top
View user's profile Send private message
VHockey86
Advanced Member


Joined: 12 Dec 2024
Posts: 988
Location: Rochester

PostPosted: Tue Sep 02, 2024 2:11 pm    Post subject: Reply with quote

should be able to take care of that with imagemagick and cropping easily enough.

http://www.imagemagick.org/Usage/crop/

Bash or python or whatever for the scripting part of it.

You can also do gimp scripts, or there's even a plugin for scripting gimp with python, but that is probably overkill and would take too long to figure out for something as simple as you're doing.
http://www.gimp.org/docs/python/pygimp.html


Back to top
View user's profile Send private message
Ephemeral
Advanced Member


Joined: 26 Jun 2024
Posts: 671
Location: UK

PostPosted: Tue Sep 02, 2024 3:18 pm    Post subject: Reply with quote

thanks thats exactly what i needed Cool


Back to top
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Tue Sep 02, 2024 3:48 pm    Post subject: Reply with quote

You could modify some of my bbips scripts to do that....

here is the url for the "crop" section dealing with imagemagick
http://www.imagemagick.org/Usage/crop/#crop

Here is a quick bash script I put together...... didn't test it, but it should do the trick i think.... you will need to modify the settings to suit your needs.

Code:

#!/bin/bash
# by Crouse 09-02-2008
# Save and run file in directory of images to be changed.
# Crops .png files to size and then changes them to .eps files.

# Check for required programs
if [[ -z $( type -p convert ) ]]; then echo -e "ImageMagick -- NOT INSTALLED !";exit ;fi
if [[ -z $( type -p sed ) ]]; then echo -e "sed -- NOT INSTALLED !";exit ;fi

# Set IFS to correct parameter
export IFS=$'\n';

# Use Imagemagick to crop images
for i in $(find . -maxdepth 1 -type f -iname "*.png");
# Change 32x32 to reflect size of image wanted, and 0+0 is offset if needed.
do
 convert ${i}  -gravity Center  -crop 32x32+0+0 +repage  ${i}
done

# Change extentions from .png to .eps
echo "Converting from .png to .eps"
match=".png";
replacewith=".eps";
for i in $( find -iname ".png" );
do
src=$i
tgt=$(echo $i | sed -e "s/$match/$replacewith/")
echo renaming $src to $tgt
mv $src $tgt
done



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11


Last edited by crouse on Wed Sep 03, 2024 7:51 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Tue Sep 02, 2024 4:44 pm    Post subject: Reply with quote

crouse wrote:
...
Code:

#!/bin/bash
# by Crouse 09-02-2008
# Save and run file in directory of images to be changed.
# Crops .png files to size and then changes them to .eps files.

# Check for required programs
if [[ -z $( type -p convert ) ]]; then echo -e "ImageMagick -- NOT INSTALLED !";exit ;fi

# Set IFS to correct parameter
export IFS=$'\n';

# Use Imagemagick to crop images
for i in $(find . -maxdepth 1 -type f -iname "*.png");
# Change 32x32 to reflect size of image wanted, and 0+0 is offset if needed.
do
 convert ${i}:  -gravity Center  -crop 32x32+0+0 +repage  $(dirname ${i})/$(basename ${i} .png).eps
done


same but converts the filename at the same time, also saves the original just in case the settings are wrong. (also doesn't depend on sed anymore only coreutils which is a dependency of imagemagick.)



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
Ephemeral
Advanced Member


Joined: 26 Jun 2024
Posts: 671
Location: UK

PostPosted: Wed Sep 03, 2024 2:28 pm    Post subject: Reply with quote

Quote:
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys4.png:': No such file or directory.
convert: missing an image filename `./Lsys4.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys6.png:': No such file or directory.
convert: missing an image filename `./Lsys6.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys5.png:': No such file or directory.
convert: missing an image filename `./Lsys5.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys3.png:': No such file or directory.
convert: missing an image filename `./Lsys3.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys7.png:': No such file or directory.
convert: missing an image filename `./Lsys7.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys8.png:': No such file or directory.
convert: missing an image filename `./Lsys8.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys1.png:': No such file or directory.
convert: missing an image filename `./Lsys1.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys.png:': No such file or directory.
convert: missing an image filename `./Lsys.eps'.
dirname ${i}
basename ${i} .png
convert: unable to open image `./Lsys2.png:': No such file or directory.
convert: missing an image filename `./Lsys2.eps'.


im getting this message from the terminal

cant see whats wrong atm


Back to top
View user's profile Send private message
rumbarg
Jr. Member


Joined: 06 Jun 2024
Posts: 69
Location: Houston, TX

PostPosted: Wed Sep 03, 2024 5:50 pm    Post subject: Reply with quote

Try removing the colon after the ${i} in this line

Code:
convert ${i}:  -gravity Center  -crop 32x32+0+0 +repage  $(dirname ${i})/$(basename ${i} .png).eps


so that it's
Code:
convert ${i}  -gravity Center  -crop 32x32+0+0 +repage  $(dirname ${i})/$(basename ${i} .png).eps


I think it snuck in - at least that got rid of the problem here.

regards,

rumbarg



_________________
sidux sidux 2024-01 - Χάος
Back to top
View user's profile Send private message
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Wed Sep 03, 2024 7:51 pm    Post subject: Reply with quote

yup.......was my fault...... sorry..... Like I said, I didn't test it Wink



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
Ephemeral
Advanced Member


Joined: 26 Jun 2024
Posts: 671
Location: UK

PostPosted: Wed Sep 03, 2024 8:37 pm    Post subject: Reply with quote

Thanks everybody that saved me a lot of time Cool

Yeah the : was the offender


Back to top
View user's profile Send private message
rumbarg
Jr. Member


Joined: 06 Jun 2024
Posts: 69
Location: Houston, TX

PostPosted: Wed Sep 03, 2024 9:57 pm    Post subject: Reply with quote

I sometimes enjoy debugging! When the bug can be found... Smile

regards,

rumbarg



_________________
sidux sidux 2024-01 - Χάος
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » OTHER All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse