1

It is possible to get a binary blob by using ImageMagick convert via PHP's shell_exec(). It's very difficult to convert such a command to PHP Imagick class. Is there any alternative way to implement this feature?

I am using Imagick like this.

$im = new Imagick('some image');
$im->trimImage(20000);
header ("Content-Type: image/{$im->getImageFormat()}");
echo $im->getImageBlob(); // need output in from of blob

I want do get output result similar to this.

convert imageName.png -alpha set -   white -border 1 -fill none -fuzz 3% -draw "color 0,0 floodfill" -shave 1x1 removed_edges.png

If ImageMagick command returns a binary blob instead of writing to a file, my problems will be solved.

4
  • 1
    You can get IM to write a PNG on stdout if that’s what you mean convert input.jpg ... PNG:- Apr 30, 2018 at 14:17
  • 1
    Why do you need the blob? If to pass to some other tool, then as Mark Setchell said, you can simply pipe the output from Imagemagick to some other tool. You should be able to create the result as a RAW RGB format rather than PNG if that is desired and pipe that by convert input.jpg .... RGB:-
    – fmw42
    Apr 30, 2018 at 16:23
  • You can use what I suggested above with ob_start() and ob_get_contents() by the way. Apr 30, 2018 at 19:55
  • Thanks @MarkSetchell I added PNG:- and now it was returning image instead of writing into file.
    – Sumeet Roy
    May 1, 2018 at 12:34

1 Answer 1

2

Appended jpg:- after command instead of image name & it's working.

$command = "convert imageName.png -alpha set - white -border 1 -fill none -fuzz 3% -draw "color 0,0 floodfill" -shave 1x1 jpg:-"; header ("Content-Type: image/jpg"); echo shell_exec($command);

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.