generate 5000+ unique image files (.jpg) of 2MB size

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Hi,
I need to generate 5000 unique image files (.jpg) of 2MB size. Can anyone help me in getting the command for generation this many unique file on x86_64 GNU/Linux Operating System. I can provide a sample image file if required.

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

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by snibgo »

Can they all be the same size, in pixels? Then use plasma or noise to create an image. Put that inside a loop.
snibgo's IM pages: im.snibgo.com
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Yes Snibgo, If all files are of almost same size then it is well and good but content should not be same. i.e all images should be unique.

I will check plasma and noise function to create these images.

If any other suggestion it will be great.

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

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by snibgo »

For example:

Code: Select all

for (( NDX=1; $NDX<10; NDX=$NDX+1 ));
do
  echo $NDX;
  convert -size 100x100 plasma: rnd_$NDX.jpg
done;
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by magick »

Use plasma:fractal to generate unique images. If you need to reproduce the sequence in the future, generate a vector of random seeds for each image and use the -seed option on your command line.
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Sure, Thanks Snibgo,

Hi Snibgo,
I am using 5 directory to run this script in parallel and each directory will generate 1000 files.So total target of 5000 files will be achieved soon.

I am sure that running from one location will generate all unique image files. Is their any change that if i run same script from 5 different directories then any image of one output directory may match in size and property of other output directory? I am using 5 directory of same machine.

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

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by snibgo »

With a random number generator, there is always a chance that two numbers will be the same. In fact, it is guaranteed to generate a number twice if you run it for long enough.

You can introduce a non-random sequential number to ensure they are unique. For example, set the top-left pixel to rgb(0,0,0) in the first image, rgb(0,0,1) in the next, and so on.

You don't need any randomness. Just use "xc:" to set the entire image to a solid colour.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by glennrp »

You can ake a random threshold background image:

Code: Select all

convert -size 1024x768 xc:green -random-threshold 1x99% background.ppm
Then do this in a loop over s="0000" through "5000"

Code: Select all

convert background.ppm -fill white  -draw 'scale 4,4 gravity center text 0,0 $s' -quality 98 image$s.jpg
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Hi Snibgo,
I believe i did almost same but generated files are not unique. The argument i passed is a number ( $I ). I passed value 4 so total 4X3=12 files got generated. but it seems all images generated by using one "colorBk" are of same property and size. So they are not unique.
=======================================
count=0

for colorBk in red blue green
do
echo "colorBk = $colorBk"
convert -size 1024x768 xc:$colorBk -random-threshold 1x99% background.ppm

for ((I=1; I<=$1; I++))
do
convert background.ppm -fill white -draw 'scale 4,4 gravity center text 0,0 "$I"' -quality 98 image$colorBk_$count.jpg
count=`expr $count + 1`
done

done
========================================

Please let me know if i am doing something wrong.

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

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by snibgo »

For the second convert, try:

Code: Select all

convert background.ppm -fill white -draw "scale 4,4 gravity center text 0,0 '$I'" -quality 98 image${colorBk}_$count.jpg
snibgo's IM pages: im.snibgo.com
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Thanks Snibgo,
It works.

Regards,
Sushil Kumar
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

For everyone who needs this code is below.

=======================================
#!/bin/sh
convert -size 1024x768 xc:green -random-threshold 1x99% background.ppm
for ((I=1; I<=5000; I++))
do
convert background.ppm -fill white -draw "scale 4,4 gravity center text 0,0 '$I'" -quality 98 /opt/Loc1/image_$I.jpg
done
exit;
=======================================
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by glennrp »

Note that "xc:green" is equivalent to "xc:#008000" not "xc:#00ff00". The latter is "lime" and would end up creating a small (18kbytes) solid lime-colored image with the number written on it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by fmw42 »

glennrp wrote:Note that "xc:green" is equivalent to "xc:#008000" not "xc:#00ff00". The latter is "lime" and would end up creating a small (18kbytes) solid lime-colored image with the number written on it.
lime is also the same as green1 (not green as glennrp said). So lime and green1 are equivalent to #00ff00 or rgb(0,255,0).
choudhary.sushil
Posts: 9
Joined: 2015-06-18T05:41:43-07:00
Authentication code: 6789

Re: generate 5000+ unique image files (.jpg) of 2MB size

Post by choudhary.sushil »

Thanks everyone. It was great help by all of you.
Post Reply