Heavy multi-commands script works, can i improve it?

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
homer314
Posts: 13
Joined: 2011-07-01T08:52:55-07:00
Authentication code: 8675308

Heavy multi-commands script works, can i improve it?

Post by homer314 »

Hi all,

based on Fred's 3dbox script i've created a commands sequence to create a 3dbox starting from a pdf. Steps Are:

1) cut off front - side - top

2) distort and merde those files

3) add a drop shadow

4) save a full size png and a smallest one

All is working fine but i'm sure there's a lot of optimization to apply to my code to "clear" it, so i'm looking for suggestion!

Thanks

Code: Select all

	$mpc = new Imagick();
	$mpc->readImage($printBox);
	$mpc->setImageFormat('MPC');
	$mpc->writeImage("fullbox.mpc');
	$mpc->destroy();

	$cmd = "convert -depth 8 -format png fullbox.mpc \
			\( +clone -crop ".($modelPxWidth - ($border*2))."x".($modelPxHeigh - ($border*2))."+".$border."+".$border." +repage  \
			-alpha set -virtual-pixel transparent -mattecolor none +distort Perspective '0,0 -498.427,-204.296  1043,0 466.7,-389.817  1043,674 422.231,188.464  0,674 -441.695,465.366' \
			-write tmp1.mpc +delete \) \
			\( +clone -crop ".$border."x".($modelPxHeigh-($border*2))."+0+".$border." +repage \
			-alpha set -virtual-pixel transparent -mattecolor none +distort Perspective '0,0 -547.114,-244.206  115,0 -498.427,-204.296  115,674 -441.695,465.366  0,674 -486.987,406.761' \
			-modulate 90 -write tmp2.mpc +delete \) \
			\( +clone -crop ".($modelPxWidth-($border*2))."x".$border."+".$border."+0 +repage \
			-alpha set -virtual-pixel transparent -mattecolor none +distort Perspective '0,0 -547.114,-244.206  1043,0 395.634,-416.837  1043,115 466.7,-389.817  0,115 -498.427,-204.296' \
			-modulate 90 -write tmp3.mpc +delete \) null:;
			
			#3dbox
			convert "tmp1.mpc tmp2.mpc tmp3.mpc -background none -layers merge +repage box.mpc; 
			
			#add drop shodow
			convert box.mpc 	\( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge  +repage final_full.png";

	exec($cmd);
	
	#the small one
	$im = new Imagick();
	$im->readImage("final_full.png");
	$im->scaleImage(500, 0);
	$im->writeImage("final.png');
	$im->destroy();
	
homer314
Posts: 13
Joined: 2011-07-01T08:52:55-07:00
Authentication code: 8675308

Re: Heavy multi-commands script works, can i improve it?

Post by homer314 »

Hi all,

any advice?

Thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Heavy multi-commands script works, can i improve it?

Post by Bonzo »

I guess you can combine these parts:

Code: Select all

 #3dbox
convert "tmp1.mpc tmp2.mpc tmp3.mpc -background none -layers merge +repage box.mpc; 
         
#add drop shodow
convert box.mpc    \( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge  +repage final_full.png";
into

Code: Select all

 #3dbox
convert "tmp1.mpc tmp2.mpc tmp3.mpc -background none -layers merge +repage  \( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge  +repage final_full.png";
The funny thing is I tried combining large codes and keeping the images in the memory and in some cases it was slower than saving temporary images and using png was as fast as miff. But that was a while ago now and I can not remember the full details.
homer314
Posts: 13
Joined: 2011-07-01T08:52:55-07:00
Authentication code: 8675308

Re: Heavy multi-commands script works, can i improve it?

Post by homer314 »

Thanks, but it seems slower than before
Post Reply