Images can't be found or read

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
immortal26

Images can't be found or read

Post by immortal26 »

Here is the code i'm running:

Code: Select all

-bash-3.2$ convert alphabet/l.png alphabet/a.png alphabet/u.png alphabet/r.png alphabet/a.png -background none +append cache/laura.png
-bash-3.2$ convert alphabet/d.png alphabet/a.png alphabet/v.png alphabet/i.png alphabet/d.png -background none +append cache/david.png
-bash-3.2$ convert -size 837x585 xc:none \ cache/laura.png -gravity north -composite \ alphabet/plus.png -geometry +0+227 -gravity north -composite \ cache/david.png -geometry +0+393 -gravity north -composite \ final/composite.png
convert: unable to open image ` cache/laura.png':  @ error/blob.c/OpenBlob/2491.
convert: unable to open file ` cache/laura.png' @ error/png.c/ReadPNGImage/3023.
convert: unable to open image ` alphabet/plus.png':  @ error/blob.c/OpenBlob/2491.
convert: unable to open file ` alphabet/plus.png' @ error/png.c/ReadPNGImage/3023.
convert: unable to open image ` cache/david.png':  @ error/blob.c/OpenBlob/2491.
convert: unable to open file ` cache/david.png' @ error/png.c/ReadPNGImage/3023.
convert: missing an image filename ` final/composite.png' @ error/convert.c/ConvertImageCommand/2970.
-bash-3.2$ ls cache/
david.png  laura.png
-bash-3.2$ ls final/
-bash-3.2$ 
as you can see the first 2 converts are creating the images david.png and laura.png in the cache folder (folder has 777 permissions)
next you see that i'm trying to create a composite image with those 2 files but it says it can't open them... at the bottom i ls'd the cache dir just you can see that they are there.

Running on Centos 5
Plesk
ImageMagick 6.6.2
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Images can't be found or read

Post by snibgo »

Oddly, each filename in the error report has a leading space. I don't use bash much; have you got backslashes in your script that AREN'T the last character on lines?

Please post the exact script.
snibgo's IM pages: im.snibgo.com
immortal26

Re: Images can't be found or read

Post by immortal26 »

It's in php, i thought i would just throw it in the command line for obvious reasons.
But here is the php code... maybe you could shed some light on it.

Code: Select all

<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

$time_start = microtime_float();



$text = "laura";
$text2 = "plus";
$text3 = "david";
$bg = 'back/Horses.jpg';
$cache = 'cache/';
$ext = '.png';
$alphabet = 'alphabet/';
$final = 'final/';

if (file_exists($cache.$text.$ext)) {
	$olay1 = $cache.$text.$ext;
}
else {
	$textarray = str_split($text);
	$createolay1 = 'convert ';
	foreach ($textarray as $t) {
		$createolay1 .= $alphabet.$t.$ext.' ';
	}
	$createolay1 .= '-background none +append '.$cache.$text.$ext;
	exec($createolay1, $result);
	$olay1 = $cache.$text.$ext;	
	echo "Overlay 1: ".$createolay1."<br />";
}
if (file_exists($cache.$text3.$ext)) {
	$olay2 = $cache.$text3.$ext;
}
else {
	$textarray = str_split($text3);
	$createolay2 = 'convert ';
	foreach ($textarray as $t) {
		$createolay2 .= $alphabet.$t.$ext.' ';
	}
	$createolay2 .= '-background none +append '.$cache.$text3.$ext;
	exec($createolay2, $result);
	$olay2 = $cache.$text3.$ext;
	echo "Overlay 2: ".$createolay2."<br />";
}

list($width1, $height1) = getimagesize($olay1);
list($width2, $height2) = getimagesize($alphabet.$text2.$ext);
list($width3, $height3) = getimagesize($olay2);

if ($width1 > $width3) $width = $width1;
else $width = $width3;

$height1 = $height1+35;
$height2 = $height2+35;

$height = $height1+$height2+$height3;

$pos1 = $height1;
$pos2 = $height1 + $height2;

$createcomp = 'convert -size '.$width.'x'.$height.' xc:none \\ ';
$createcomp .= $olay1.' -gravity north -composite \\ ';
$createcomp .= $alphabet.$text2.$ext.' -geometry +0+'.$pos1.' -gravity north -composite \\ ';
$createcomp .= $olay2.' -geometry +0+'.$pos2.' -gravity north -composite \\ ';
$createcomp .= $final.'composite.png';

echo "Create Comp: ".$createcomp."<br />";

$resize = 'convert '.$final.'composite.png -resize 1188x408 '.$final.'composite.png';

echo "Resize: ".$resize."<br />";

$finalout = 'convert '.$bg.' -geometry +0+230 -gravity north composite.png -composite '.$final.'final.jpg';

echo "Final Out: ".$finalout."<br />";

exec($createcomp, $result);
exec($resize, $result);
exec($finalout, $result);
//exec('rm '.$final.'composite.png', $result);




$time_end = microtime_float();
$time = $time_end - $time_start;

echo "Took ".$time." seconds to render image";
echo "<br /><img src='final/final.jpg'>";





function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}


?>
immortal26

Re: Images can't be found or read

Post by immortal26 »

wow it was the spaces... i would have thought it would toss the spaces out... should it not be done through bash?
So the problem is solved but still curious if i should set the domain settings to use something besides bash to prevent this from happening again.

Thanks for that good eye.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Images can't be found or read

Post by snibgo »

In bash, when the final character in a line is backslash, it means "ignore the newline". These backslashes aren't the final characters, because they are followed by a space, and there is no newline within the string.
snibgo's IM pages: im.snibgo.com
immortal26

Re: Images can't be found or read

Post by immortal26 »

would sh be a better route to take? or?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Images can't be found or read

Post by snibgo »

I doubt it. Just remember which language each component is in, and follow the rules. You are building createcomp as a command in one long string, so it doesn't need "\\".
snibgo's IM pages: im.snibgo.com
immortal26

Re: Images can't be found or read

Post by immortal26 »

Yeah i know, just makes my code look a little cleaner ;)
Thanks for the help.
I just have one more question and don't want to start a new thread since it's nothing to serious but...
That one long string doesn't seem to be conserving some of the transparency from the png... but at the same time it's preserving most of it... just little hints here and there. I tried placing a -background none somewhere in there but didn't take.
Something I'm missing about the comp i'm missing?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Images can't be found or read

Post by snibgo »

As far as I can see, the command

Code: Select all

convert -size 837x585 xc:none cache/laura.png -gravity north -composite alphabet/plus.png -geometry +0+227 -gravity north -composite cache/david.png -geometry +0+393 -gravity north -composite final/composite.png
should work, preserving transparency.

Please post lara.png, plus.png and david.png.
snibgo's IM pages: im.snibgo.com
Post Reply