How to use ImageMagick in PHP on WordPress

I am developing a WordPress plugin which requires ImageMagick.

I was testing ImageMagick on my server with this code:

Read More
<?php
/*
Plugin Name: IM Trial
/

add_action('admin_menu','admin');

function admin() {
add_submenu_page( 'options-general.php', 'Watermark', 'Watermark', 'manage_options',     'handle-uploads-admin111', adminxy );
}

function adminxy() {

$input = site_url('/wp-content/plugins/New/earth_310.png');

if($input){
echo 'Input fetched';
}
else{
echo 'Probs';
}

$output = site_url('/wp-content/plugins/New/output.png');

exec("convert $input $output");
exec("/usr/bin/convert $input $output");
}
?>

I am running my wordpress on Hostgator and they told me that ImageMagick is installed on my server. But, the above code does not give me any output. Actually, it should be creating a new image file ‘output.png’ in /plugins/New folder. But, it is neither giving any error message nor outputting the image.

Is there something I am lacking in the code??? I appreciate any help.

Related posts

Leave a Reply

1 comment

  1. First thing, you’re using the HTTP address in the command line, which doesn’t work. you must use the absolute path, so use

    ABSPATH.'/wp-content/plugins/New/earth_310.png';
    

    Nextly, I notice that you’re attempting to do a watermark. I used the GD library in my last watermarking class. Here’s the code on github, maybe it will be of some use educationally, or usefully.

    https://gist.github.com/2045951