Imagemagick API

Imagemagick has hundreds, no, thousands, no...infinite opportunities, for modifying, creating and transforming images and text. Usually run from the command line, an API is also provided through php for running on linux servers. This opens things up for making use of Imagemagick with AI2 apps, whether it be for user generation, or for app development. There are several extensions for handling image manipulation, most notably Taifun's Image Extension and Metadata Extension, along with Mika's Image Editor, but neither of these come even close to what can be done with Imagemagick (however I will recommend Taifun's Image Extension for use in the Imagemagick process later).

It would be nigh on impossible to provide a point and press UI to handle all the options for Imagemagick, it therefore makes sense to cherry pick for specific requirements or to provide a library (IM Examples) and to set the parameters in text.

The aim here is to show what is required to make use of Imagemagick, and then some examples of how it could be used in apps, some of these based upon developer requests / enquiries on the forums. I have not included any options for batch processing of images, but this could be done using a version of the file by file method.

For speed and bandwidth, try to keep output images as small as necessary/possible. Remember the screen size of android devices.

SETUP

API Requirements:


APP Requirements:

BLOCKS and PHP CODE

I will show below the php file and the blocks required for each approach. The Web1.GotFile blocks are the same for all three types, simply setting Image1.Picture to the file returned (imtmp.png). For simplicity's sake, I have built the convert command in join blocks so you can see all the elements. in practice, it would make more sense to return the intended command to a textbox, so that the user could edit it before sending for conversion, and you would probably be using variables for the various parts of the command - e.g. the original filename.

IMAGES

<?php


header('Content-Type: image/png');


  $data = file_get_contents('php://input');

  $filename = $_GET['filename'];

  $command =  $_GET['command'];


  if (file_put_contents($filename,$data)) {

    if (filesize($filename) != 0) {

      

      passthru( $command );

    } 

  } 


if (!unlink($filename)) {

  }

else {

  }


?>

Google Drive

I have split up the google drive file to two parts, in order that I can simply use the file ID returned by a script from google. Because this one all happened on the web you can use larger file sizes stored on google.

<?php


header('Content-Type: image/png');


  $url = $_GET['url'];

  $id = $_GET['id'];

  $url = $url."&id=".$id;

  $data = file_get_contents($url);

  $filename = $_GET['filename'];

  $command =  $_GET['command'];

  

  if (file_put_contents($filename,$data)) {

    if (filesize($filename) != 0) {

      

    passthru( $command );


  } 

}


if (!unlink($filename)) {

  }

else {

  }


?>

TEXT/LABELS/CAPTIONS

<?php


header('Content-Type: image/png');


    passthru( $_GET['command'] );


?>

For the conversion of text, and to make labels and captions, the command passes the properties and the text, in the above example the word "AppInventor", and returns an image in the same way as image conversions

CONCLUSION

The ability to be able to use ImageMagick through Appinventor opens up a world of possibilities for image manipulation and conversion, and for the creation of image labels and images of text. It will help to overcome some of the blockages developers find when creating their apps.

Refer to IM EXAMPLES for ideas about what can be done

Examples Pages on METRIC RAT