1

I'm using the Image Workshop plugin with composer in codeigniter. http://phpimageworkshop.com/

I've created a helper and linked this to my controller. The helper creates an ID card and then shows it to the user. However when it tries to find the jpeg to watermark I get this error:

File "http://localhost/test_files/Codeigniter/assets/images/juniorLicenceFront.png" not exists.

If I visit that exact URL the image that I want to write over shows up.

use PHPImageWorkshop\ImageWorkshop;

function printLicence($licence_num, $first_name, $last_name, $club, $expiry) {
    $licenceFront = "juniorLicenceFront.png";

    $files = base_url();
    $layer = ImageWorkshop::initFromPath($files.'assets/images/'.$licenceFront);

    // This is the text layer
    $licenceNumLayer = ImageWorkshop::initTextLayer($licence_num, $files.'assets/Futura-Md-BT-Bold.ttf', 55, '#ea1d25', 0);
    $licenceNumLayer->rotate(90);

    $nameLayer = ImageWorkshop::initTextLayer("{$first_name}{$last_name}", $files.'assets/arial.ttf', 27, '333333', 0);
    $clubLayer = ImageWorkshop::initTextLayer($club, $files.'assets/arial.ttf', 27, '333333', 0);
    $expiryLayer = ImageWorkshop::initTextLayer($expiry, $files.'assets/arial.ttf', 27, '333333', 0);

    $layer->addLayerOnTop($licenceNumLayer, 40, 60, "RT");
    $layer->addLayerOnTop($nameLayer, 200, 255, "LB");
    $layer->addLayerOnTop($clubLayer, 200, 198, "LB");
    $layer->addLayerOnTop($expiryLayer, 200, 142, "LB");

    $image = $layer->getResult();
    header('Content-type: image/png');
    imagepng($image);
    imagepng($image, "card.png"); 
    exit;    
}

?>

A solution would be greatly appreciated I've spent many hours on this.

Luke.T
  • 600
  • 1
  • 5
  • 24
  • What does base_url() return? – cjs1978 May 09 '17 at 20:56
  • It's returning this http://localhost/test_files/Codeigniter/ @cjs1978 – Luke.T May 09 '17 at 21:07
  • The error comes from these lines in ImageWorkshop: public static function initFromPath($path, $fixOrientation = false) { if (false === filter_var($path, FILTER_VALIDATE_URL) && !file_exists($path)) { throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND); } – cjs1978 May 09 '17 at 21:10
  • Are you by any chance seeing a cached version of the image when you visit the URL in your browser? – cjs1978 May 09 '17 at 21:13
  • ... and does base_url() return "localhost/test_files/Codeigniter" without http:// in front? – cjs1978 May 09 '17 at 21:14
  • I've just cleared cache and the image still showed so I don't think so. Yes it does include http:// it was auto removed by stackoverflow – Luke.T May 09 '17 at 21:21
  • 1
    If I were to debug this, I would take the statements in `if (false === filter_var($path, FILTER_VALIDATE_URL) && !file_exists($path))` and debug one by one to see which one fails with the path to the image as argument. Does file_exists() work with URLs - if not, try to use the $_SERVER["DOCUMENT_ROOT"]."..." path to the image. – cjs1978 May 09 '17 at 21:30
  • Thanks for your help, as you said file_exists() doesn't work with URL's and that's why it wouldn't work. I've changed the file paths now and it works fine.@cjs1978 – Luke.T May 09 '17 at 21:46

0 Answers0