I personally use a custom 404 page inside a PHP application.

On that 404 page, I check for several 'known' older pages that no more exist, after which redirect user to more recent or best current page. Is effective.

Now i'm confronted with a number of old images which have been removed, and am searching for a method to redirect the pictures to a different image (all within the php code if at all possible).

I've hunted around briefly and emerged empty.

Any method of doing this?

This is a sample of my code:

<?php
    //-- grab info regarding bad request --
    $root	  	= $_SERVER['DOCUMENT_ROOT'];
    $page 	  	= parse_url($_SERVER['REQUEST_URI']);
    $page	  	= $page['path'];
    $referer 		= $_SERVER['HTTP_REFERER'];
    $host	  	= $_SERVER['REMOTE_HOST'];

    //-- try to redirect old pages/files ----------------------
    //
    $page = urlencode($page);

    if ( stristr($page, "some_old_file.zip") ) {
    	// Example file redirect
    	echo 	"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site.com/the/new/file.zip\">";

    } elseif ( stristr($page, "some_old_page.php") ) {	
    	// example webpage redirect
    	echo 	"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site.com/the/new/page.php\">";

    } elseif ( stristr($page, "some_old_image.jpg") ) {
    	// not sure how to do this ...
    	// ...
    	// ...
    	// ...
    	// ...
    	// ...
    	// not sure how to do this ...    		
    } else {
    	// everything else - direct to custom 404 search page
    	echo 	"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site/com/the/custom/404_help.php?page={$page}\">";
    }
    //
    // -------------------------------------------------------

?>

rather than outputting a meta refresh, make use of a location header

header("Location: /path/to/image.jpg\r\n");

The rn is simply a new line to delimit the headers.

Note: headers should be sent before every other output

You'll need server side redirect. Browse around php function "header" and http status code 301 (moved permanently). You will find a lot of ready to use 5 lining solutions.

Personally, I'd make use of this way of html content too to see the search engines like google concerning the new location of the identical content.

My recommendation is always to do that inside Apache using Apache redirects (inside your Apache conf files or .htaccess). That you can do something similar to this:

RedirectMatch old_file_path new_file_path

This won't enhance your performance however, you will not need to perform a research every time. The best of this is it is going to be workable should you have to increase the missing redirects later on.