Redimensionar imagem e exibir sem salvá-lo

Eu construí uma galeria de imagens e salvei a imagem "como está" sem cortá-la. Eu quero redimensionar a imagem enquanto ela é carregada no controlador, então quando eu carrego o controlador no navegador, ele exibe a imagem redimensionada para o que eu quiser. Eu adicionei o método paraMY_Loaderaqui está o código.

function show_image($image, $width, $height) {
    $this->helper('file');
    $image_content = read_file($image);

    //resize image
    $image = imagecreatefromjpeg($image);
    $thumbImage = imagecreatetruecolor(50, 50);
    imagecopyresized($thumbImage, $image, 0, 0, 0, 0, 50, 50, $width, $height);
    imagejpeg($thumbImage,"",85);
    imagedestroy($image);
    imagedestroy($thumbImage);

    header('Content-Length: '.strlen($image_content)); // sends filesize header
    header('Content-Type: '. get_mime_by_extension($image)); // send mime-type header
    header('Content-Disposition: inline; filename="'.basename($image).'";'); // sends filename header
    exit($image_content); // reads and outputs the file onto the output buffer
}

A partir desse código, estou recebendo muitos erros, incluindo erros de cabeçalho. O que estou fazendo de errado?

Erros: (se útil)

Message: imagejpeg(): Filename cannot be empty

Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)

Message: strrchr() expects parameter 1 to be string, resource given

Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)

Message: basename() expects parameter 1 to be string, resource given

Message: Cannot modify header information - headers already sent by (output started at /Volumes/www/vhosts/ci/system/core/Exceptions.php:185)

questionAnswers(1)

yourAnswerToTheQuestion