Studio libraray and utility error

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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Studio libraray and utility error

Post by Bonzo »

I have a problem with my Imagemagick install on my localhost - it used to work OK but since installing another program the .miff format seems to causing a problem.

Its a Vista 32bit computer using XAMPP and the miff is working OK through a batch file and command box.

The error I get is:
Image
Image

This code used to run OK and it still does run up to the area marked ****** where I get the errors above. The cropped images are created and then the program exits.
I can resize to a jpg thumbnail and png but if I try to resize to a miff I get the above error again.

Code: Select all

<?php
//unlink('combined.png');

// Original image
$image = 'original/bridge.jpg';

exec("convert $image -thumbnail 800x800 output.png");

$image = "output.png";

// Amount of images in x
$qty_x = '5';

// Amount of images in y
$qty_y = '4';

// Get the size of the original image
$size = getimagesize($image);

// Size to crop the images to 
// code modified as per sugestion of Dave to prevent problems with left over parts of the divided image.
$crop_x = round( $size[0]/$qty_x + 0.5);
$crop_y = round( $size[1]/$qty_y + 0.5 );

// Canvas for combined images - it will be trimmed to the finished image size in the code
$width = ( $size[0] * 1.5 );
$height = ( $size[1] *1.5 );

// Crop the image
exec("convert $image -crop {$crop_x}x{$crop_y} image-%d.jpg"); 

******
// Remove the .jpg from the filenames
foreach (glob("*.jpg") as $filename) {
$file = str_replace('.jpg', '', $filename );
$rotate = mt_rand(-5, 5);
    exec("convert $filename -background none -rotate $rotate $file.miff");
	
	$deviation = exec("convert $filename -format \"%[standard_deviation]\" info:");
	//$deviation = exec("convert $filename -format \"%[fx:standard_deviation]\" info:");
	echo "<img src=\"$filename\">".$deviation;
	
	// Bridge below
	if ( $deviation < '5800' ){ 
	// small.jpg below
	//if ( $deviation < '15700' ){ 
	//if ( $deviation < '0.029' ){ 
	$dim = exec("convert $file.miff -format \"%wx%h\" info:");
	exec("convert -size $dim xc:none $file.miff");
	}
}


// Delete tempory images
foreach (glob("*.jpg") as $filename) {
//unlink($filename); 
}

// Set $command variable
$command = "";

// Loop through generating the image layout
for ($j = 0; $j < $qty_y; $j++) { 

  for ($i = 0; $i < $qty_x; $i++) {    $n = $j>0 ? $qty_x*($j)+$i : $i; 
  $offset_x= ( ($crop_x * $i ) + mt_rand(-1, 1));
  $offset_y=( ($crop_y * $j ) + mt_rand(-1, 1));
  $command .= " image-$n.miff -geometry +$offset_x+$offset_y -composite" ;  } 
  }

// Produce the combined image
exec( "convert -size {$width}x{$height} xc:none $command -trim combined.png"); 

// Delete tempory images
foreach (glob("*.miff") as $filename) {
unlink($filename); 
}


?> 
<br><br>
<img src="combined.png">
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Studio libraray and utility error

Post by Bonzo »

I have looked at this again and the .miff images are created - I forgot I was deleting them :?

The last image is not created which is this line:

Code: Select all

// Produce the combined image
exec( "convert -size {$width}x{$height} xc:none $command -trim combined.png");
The command variable is created and the .miff files are deleted so the whole code is running just as I say the last image is not created and Imagemagick is exiting with the error.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Studio libraray and utility error

Post by Bonzo »

Seems it was a bug in the version 6.7.2 I upgraded to last week. Upgrading to 6.7.3 removes the error and the code runs OK.
Post Reply