Question

I am using ImageMagick to make a Turing Number, becauase PHP GD just isn't powerful enough to do the things that we want. My question is, how can I use ImageMagick to run different commands on my image at different points in my code? For example is it possible to write to memory, then load from memory without writing to file?

So, for example if I run this to build my background:

exec("/usr/local/bin/convert '$this->background' -resize $this->width :save_to_mem:");

I don't want to save the file if I don't have to. Next I want to reference the file within a loop, maybe like this:

$text = $this->turing;
exec("/usr/local/bin/convert :load_from_mem: -size {$this->width}x{$this->height} -xc:white :save_to_mem:");
for($i = 0; $i < strlen($text); $i++){
    $number = randNum();
    exec("/usr/local/bin/convert :load_from_mem: -font Candice -pointsize 72 label:$number :save_to_mem:");
}

After that I would like to write the file to php's output buffer to display on the page. Is any of this possible?

No correct solution

OTHER TIPS

Imagemagick does support memory program register (mpr:) for writing & reading images in memory. However, anything allocated in memory will be freed at the end of the process, so a bit forethought will be needed to design your solution.

convert rose: -write mpr:apples +delete \
    \( mpr:apples -rotate 90 \) \
    \( mpr:apples -rotate 120 \) \
    mpr:apples +append aa_rose.png

mpr: example

Another alternative is to mount a portion of volatile memory as a directory with tmpfs, and write your temporary images there.

#/etc/fstab
tmpfs /var/imagemagick-tmp tmpfs nodev,nosuid,size=50M 0 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top