Jump to content

Php page image with text rewritten to function but...


Pruus
Go to solution Solved by gizmola,

Recommended Posts

I have a php code to add text on a image. Now i want to make a function to save the image, to use it several times in my code. But it does not work.

 

function maakafbeelding($n1, $n2, $n3) {

Header ("Content-type: image/jpeg");

switch ($n3):
     case "1":
     $image = imageCreateFromJPEG("images/basis-rood.jpg");
     break;
     case "2":
     $image = imageCreateFromJPEG("images/blauw.jpg");
     break;
     case "3":
     $image = imageCreateFromJPEG("images/infrastrutuur.jpg");
     break;
     case "4":
     $image = imageCreateFromJPEG("images/park.jpg");
	 break;
	 case "5":
     $image = imageCreateFromJPEG("images/Suteki.jpg");
	 break;
	 default:
     $image = imageCreateFromJPEG("images/basis.jpg");
endswitch;

$color = ImageColorAllocate($image, 255, 255, 255);
$color1 = ImageColorAllocate($image, 169, 169, 169);

//  Wrtie text to horizontal alignment for the names.
imagettftext($image, 70, 0, 150, 185, $color, 'font/HermesRegular.ttf', $n1);
imagettftext($image, 40, 0, 500, 240, $color1, 'font/HermesRegular.ttf', $n2);
// nu opslaan
imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80);
// vernietig file in geheugen
ImageDestroy($image);
}.
Where do i go wrong? Edited by Pruus
Link to comment
Share on other sites

  • Solution

You should not be outputting an image header in a script that is simply creating an image and writing it to disk. Remove the

 

Header ("Content-type: image/jpeg");
The other thing to look into is the path:

 

imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80);
Make sure that whatever process is running this php code has rights to rwx the vda-images directory.
Link to comment
Share on other sites

I have changed the header and it works now. Thanks. The working code:

function maakafbeelding($n1, $n2, $n3) {

// Header ("Content-type: image/jpeg");

switch ($n3):
     case "1":
     $image = imageCreateFromJPEG("images/basis-rood.jpg");
     break;
     case "2":
     $image = imageCreateFromJPEG("images/basis-blauw.jpg");
     break;
     case "3":
     $image = imageCreateFromJPEG("images/infrastructuur.jpg");
     break;
     case "4":
     $image = imageCreateFromJPEG("images/park.jpg");
	 break;
	 case "5":
     $image = imageCreateFromJPEG("images/suteki.jpg");
	 break;
	 default:
     $image = imageCreateFromJPEG("images/basis.jpg");
endswitch;

$color = ImageColorAllocate($image, 255, 255, 255);
$color1 = ImageColorAllocate($image, 169, 169, 169);

//  Wrtie text to horizontal alignment for the names.
imagettftext($image, 70, 0, 150, 185, $color, 'font/HermesRegular.ttf', $n1);
imagettftext($image, 40, 0, 500, 240, $color1, 'font/HermesRegular.ttf', $n2);
// nu opslaan
imagejpeg($image, 'vda-images/topbanners/'.$n1.'.jpg', 80);
// vernietig file in geheugen
ImageDestroy($image);
return;
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.