Page 1 of 1

Magickwand

Posted: 2008-04-16T07:58:33-07:00
by nonaguy
We have some php to convert a tiff into a jpeg, all in memory, and echo out the results via a web application. Here is the code:

<?php
$resolution=$_GET["res"];
$presize=($resolution*2);
$photo="test.tif";
$cmd = "convert \"$photo\" -scale 50% -strip -unsharp 0.2x0.6+1.0 -quality 87 JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>

Does anyone know how to rewrite this using Magickwand? We are trying to shave a few seconds off the conversion and we are oping this will help. Thank you.

Re: Magickwand

Posted: 2008-04-16T19:11:34-07:00
by el_supremo
I don't know how to do that with PHP but here's C code and perhaps you can translate it.

Code: Select all

void test_wand(void)
{
	MagickWand *m_wand;
	unsigned long width,height;

	MagickWandGenesis();
	m_wand = NewMagickWand();

	// Read one of my TIF images
	MagickReadImage(m_wand,"DOWO.tif");

	width = MagickGetImageWidth(m_wand);
	height = MagickGetImageHeight(m_wand);
	MagickScaleImage(m_wand,width/2,height/2);

	MagickStripImage(m_wand);
	
	// 0.05 is the default threshold when none is specified on the command line
	MagickUnsharpMaskImage(m_wand,0.2,0.6,1.0,0.05);

	MagickSetImageCompressionQuality(m_wand,85);
	
	MagickWriteImage(m_wand,"DOWO.jpg");
	m_wand = DestroyMagickWand(m_wand);
	
	MagickWandTerminus();
}
I couldn't figure out what the $presize was for - your code doesn't seem to use it.

Best Wishes
Pete