Closed chrbono closed 10 years ago
I have tried another code as showed in the tutorial and it saves the image edited in a folder, that works beautiful. But what I am getting is a blank thumbnail. I would like that the image is displayed on the web browser to let the user view the image before save. this is my code.
<?php ini_set('display_errors', 'On');error_reporting(E_ALL); use PHPImageWorkshop\Imageworkshop;
require_once('PHPImageWorkshop/ImageWorkshop.php'); require_once('PHPImageWorkshop/Core/ImageWorkshopLayer.php'); require_once('PHPImageWorkshop/Exception/ImageWorkshopException.php'); require_once('PHPImageWorkshop/Core/ImageWorkshopLib.php');
$pinguLayer = ImageWorkshop::initFromPath('PHPImageWorkshop//pingu.jpg');
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
$wwfLogoLayer = ImageWorkshop::initFromPath('images/Google-icon.jpg'); $tuxLayer = ImageWorkshop::initFromPath('images/Mylogolow.gif'); $tuxLayer->resizeInPixel(100, null, true);
// resize pingu layer $pinguLayer->resizeInPixel(400, null, true);
// Add 2 layers on pingu layer $pinguLayer->addLayerOnTop($wwfLogoLayer, 20, 10, 'LB');//LB== Left bottom $pinguLayer->addLayerOnTop($tuxLayer, 20, 10, 'RT');//RT = Right Top
// Saving the result $dirPath =" ImageworkshopUploads"; $filename = "pingu_edited.png"; $createFolders = true; $backgroundColor = null; // transparent, only for PNG (otherwise it will be white if set null) $imageQuality = 95; // useless for GIF, usefull for PNG and JPEG (0 to 100%)
$pinguLayer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality);
$image = $pinguLayer->getResult(); //header('Content-Length: '.filesize($image)); header("Content-type: image/jpeg"); //print file_get_contents($image); imagejpeg($image, null, 95); // We chose to show a JPG with a quality of 95% ?>
I found what was wrong. I removed
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
and now it works
ini_set('display_errors', 'On');error_reporting(E_ALL);
require_once(DIR.'/PHPImageWorkshop/ImageWorkshop.php'); use PHPImageWorkshop\ImageWorkshop;
//var_dump(file_exists('PHPImageWorkshop/banner1.jpg'));// breaks the header output log it elsewhere using a file logger //var_dump(class_exists('PHPImageWorkshop\ImageWorkshop'));// breaks the header output log it elsewhere using a file logger
$layer=ImageWorkshop::initFromPath('PHPImageWorkshop/banner1.jpg'); //var_dump(get_class($layer)); // breaks the header output log it elsewhere using a file logger //echo $layer->getWidth();// breaks the header output log it elsewhere using a file logger //echo $layer->getHeight();// breaks the header output log it elsewhere using a file logger
$layer->resizeInPixel(400, null, true);
$image = $layer->getResult(); header('Content-type: image/jpeg'); imagejpeg($image, null, 95); // We chose to show a JPG with a quality of 95%
you can't have echos or var_dump in a picture file it don't work you could try throwing exceptions on errors so you would know if something fail by visual output when it is rendered in a broswer but that would be the only way, or have to scripts files on test file the other the production file
On Tue, Apr 8, 2014 at 12:59 PM, chrbono notifications@github.com wrote:
I found what was wrong. I removed
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
echo $pinguLayer->getWidth(); echo''; echo $pinguLayer->getHeight(); echo'';
and now it works
Reply to this email directly or view it on GitHubhttps://github.com/Sybio/ImageWorkshop/issues/38#issuecomment-39887754 .
//Test.php:
<?php
$Test = True; require_once(Production_File.php);
var_dump(file_exists('PHPImageWorkshop/banner1.jpg')); var_dump(class_exists('PHPImageWorkshop\ImageWorkshop')); var_dump(get_class($layer))
echo $layer->getWidth(); echo $layer->getHeight();
?>
//Production_file.php:
<?php
ini_set('display_errors', 'On');error_reporting(E_ALL);
require_once(DIR.'/PHPImageWorkshop/ImageWorkshop.php'); use PHPImageWorkshop\ImageWorkshop;
$layer=ImageWorkshop::initFromPath('PHPImageWorkshop/banner1.jpg'); $layer->resizeInPixel(400, null, true);
$image = $layer->getResult();
if(!isset($Test)){// if this file is loaded by test.php then $test will be set. header('Content-type: image/jpeg'); imagejpeg($image, null, 95); // We chose to show a JPG with a quality of 95% }
Just to note the best way to do this is to make 2 classes on the logic and one the test and then us methods etc to test the system. please read up on Test Driven Development
Hi, I am a beginner using php, I am getting no image display. I did the test script and it seems that everything is OK, but actually I am doing something wrong because it is not working. This is my code.
<?php ini_set('display_errors', 'On');error_reporting(E_ALL); use PHPImageWorkshop\Imageworkshop;
require_once('PHPImageWorkshop/ImageWorkshop.php'); require_once('PHPImageWorkshop/Core/ImageWorkshopLayer.php'); require_once('PHPImageWorkshop/Exception/ImageWorkshopException.php'); require_once('PHPImageWorkshop/Core/ImageWorkshopLib.php');
var_dump(file_exists('PHPImageWorkshop/banner1.jpg')); echo '';
var_dump(class_exists('PHPImageWorkshop\ImageWorkshop')); echo'';
$layer=ImageWorkshop::initFromPath('PHPImageWorkshop/banner1.jpg'); var_dump(get_class($layer)); // test echo $layer->getWidth(); echo $layer->getHeight();
$layer->resizeInPixel(400, null, true);
$image = $layer->getResult(); header('Content-type: image/jpeg'); imagejpeg($image, null, 95); // We chose to show a JPG with a quality of 95%
?>
I am getting a thumbnail with no image. If I comment the last 3 lines this is the result.
bool(true) bool(true) string(40) "PHPImageWorkshop\Core\ImageWorkshopLayer" 1000221
Can someone help? Tell me what I am doing wrong.