Jump to content

[SOLVED] Several 'headers'


mrcodex

Recommended Posts

I've read FAQ and tried several things, but can not get this to work ...

 

How get I use several e.g. GD 2 scripts at the same page? like this:

 

<?php

$im = imagecreatetruecolor(120, 20);

$text_color = imagecolorallocate($im, 233, 14, 91);

imagestring($im, 1, 5, 5,  'test1', $text_color);

header('Content-type: image/jpeg');

imagejpeg($im, NULL, 75);

imagedestroy($im);

 

$im = imagecreatetruecolor(120, 20);

$text_color = imagecolorallocate($im, 233, 14, 91);

imagestring($im, 1, 5, 5,  'test2', $text_color);

header('Content-type: image/jpeg');

imagejpeg($im, NULL, 75);

imagedestroy($im);

?>

 

I'm new at PHP, jumping right from ASP ...

 

rgrds,

 

Link to comment
Share on other sites

It's mainly to crop images. I have a chat-script (shoutbox kind) that display the chat-text and image of the user. Now I have locked the size of the user-images, but I want to crop them to get the right aspect/ size for my site. I've found several crop-script, but get stuck on the header-thing. So I thought of trying out a simple GD example first. I want to crop and display them instead of crop and save.

 

thx

Link to comment
Share on other sites

You need to use the <img> tag specifying a php script as the src. It can be the same script.

 

Example:

<?php
if (isset($_GET['im'])) {
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  $_GET['im'], $text_color);
header('Content-type: image/jpeg');
imagejpeg($im, NULL, 75);
imagedestroy($im);
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>PHP Image Test</title>
</head>
<body>
<img src="?im=test1"><br><img src="?im=test2">
</body>
</html>

 

Ken

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.