Page 1 of 1

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

Posted: 2014-12-27T10:35:30-07:00
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();
	

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

Posted: 2015-01-01T07:16:36-07:00
by homer314
Hi all,

any advice?

Thanks

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

Posted: 2015-01-01T07:25:07-07:00
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.

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

Posted: 2015-01-02T12:59:58-07:00
by homer314
Thanks, but it seems slower than before