2

In the below code , iam trying to output a image through imagemagick processing. Here, iam applying a border radius to the input image. I am getting the output when iam saving a image to the output folder with the following code.

<?php
$input = "input.png";
$s = 10;
$t = 10;
$size = getimagesize ( $input );
$output = $outputfolder . $outputname;
exec( "convert -size " . $size [0] . "x" . $size [1] . " xc:none -fill -transparent 
-draw \"roundRectangle 0,0 " . $size [0] . "," . $size [1] . " $s,$t\"  " . $input .
" -compose SrcIn -composite " . $output . " " );
?>

I want a output which has not been saved to the local folder but want to display the output with the header content type. Iam using passthru to do this.But iam not getting the output. I am trying with the following code

    <?php
$input = "input.png";
header("Content-Type: image/png");
$size = getimagesize ( $input );
$s = 10;
$t = 10;
$cmd =  " - size " . $size [0] .
              "x" . $size [1] . " xc:none -fill -transparent  -draw
\"roundRectangle 0,0 " .
                $size [0] . "," . $size [1] . " $s,$t\"  " .
                 " -compose SrcIn -composite" .
                " -tile - $input";

passthru("convert $cmd PNG :-")

?>

I think i am wrong with the command i used. Please help me in this. Thanks in advance.

RaviSankar
  • 31
  • 1
  • 2
  • 1
    echo out the command, and run it manually via the console and see if the command outputs what you are expecting. if the command produces no data, it wont pass anything to passthru – bizzehdee Mar 18 '13 at 13:19

1 Answers1

0

Can you explain your reasoning behind now wanting to save the file? For what purpose is the image being converted?

Until I get that extra info, I will go out on a limb and assume that image is being uploaded as part of a CMS and being tweaked to fit the layout, and then to be displayed to users?

If that is the case personally I would save the output file, then do something like to display it.

header("Content-Type: image/png");
echo file_get_contents($pathToImage)

You can do a check to see if the file already exists before running image magick it. That will likely run more efficiently than keeping reprocessing the image every time it is displayed

CodeMonkey
  • 3,271
  • 25
  • 50