Advanced Usage

Remote Image Manipulation

How To Use A Remote Image

CE Image makes working with remote images very easy. Simply pass in a full URL as the source parameter (for example: src="http://www.example.com/some_image.png").

How Is This Possible?

PHP can only manipulate images that are on the local server. So if an image is located on another server, it must first be downloaded to your server before it is manipulated. The caveat here is that if the images are too large (depending on your configuration and hardware), PHP may have difficulties copying the image over. If the image is 1000px by 1000px or less, your configuration should be able to grab and cache the remote image gracefully.

In order to determine if an image is remote or not, it must be compared to the current domain. In general, this should happen automatically, but if you have any troubles, you can specify the current domain, by assigning a value to the 'current_domain' key in the $factory_defaults array near the top of the Ce_image.php file (initially set to ''), or override it in the settings at any point.

What If The Remote Image Changes?

One of the great things about CE Image, is that it strives to keep your manipulated images up-to-date. Please take a look at the remote_cache_time setting to see how you can control how CE Image checks for updates (or not) for your remote images. The remote_cache_time can be set by changing the 'remote_cache_time' value in the $factory_defaults array near the top of the Ce_image.php class, or overriding it via the settings.

Multiple Processing

On rare occasions, if ever, you may want to process an image multiple times. For example, let’s say for some reason, you really wanted to add a border to an image twice. Here’s how to do it. We’re going to assume the class is already instantiated above.

//make the image, but don't save it to a file (third param is FALSE)
$ce_image->make( '/images/example/cow_square.jpg',
        array(
                'border' => array( 4, '#fff' )
        ),
        FALSE
);

//get the image resource
$resource = $ce_image->get_resource();

//we will not close the image, or the handle will be deleted,
//and we would lose our image data!

//make the image again, passing in the resource as the source
//this time the image will be saved (third param defaults to TRUE)
$ce_image->make( $resource,
        array(
                'border' => array( 4, '#00a6e7' )
        )
);

//create the tag
echo $ce_image->create_tag();
//now we can close it
$ce_image->close();

The above code will result in:

Note: If you need the created image data resource, even after you close the image, you will want to use the following before calling the close method:

$resource = $ce_image->clone_resource();

Order Of Operations

This plugin gives you a tremendous amount of flexibility in how you manipulate images, but it does have to decide which parameters to process first. Understanding this order can be useful when figuring out how to achieve your desired outcome. The following is the order of operations for the plugin:

  • background color
  • size, crop, and flip
  • filters (processed in the order they were passed in)
  • watermark
  • borders & rounded corners
  • reflection
  • rotation
  • ASCII Art
  • average color
  • top colors

Please note that if one or more of the above operations is not requested in the settings, it is effectively skipped. Other operations are available via the various methods