Reply to Re: Mixing Php's imagecopy and HTML

Your name:

Reply:


Posted by Ubantu Rococo on 01/25/06 15:38

"d" <d@example.com> wrote in message
news:m5KBf.8888$wl.8380@text.news.blueyonder.co.uk...
> "Ubantu Rococo" <paul.x.lee@baesystems.com> wrote in message
> news:43d767e6$1_1@glkas0286.greenlnk.net...
>> >
>>> I don't think imagejpeg works as you think it does. It outputs an
>>> image's actual binary data, so you're essentially trying to output a
>>> jpeg image with HTML tags before and after it - which won't work. What
>>> you need to do, is put the PHP code only into a file, called say
>>> image.php. Then, in your HTML document (the rest of the code above),
>>> just put an image tag in: <img src="image.php">. That will display the
>>> image in the HTML page. You can even have javascript to work out where
>>> you click on the image, and then update its url like this:
>>>
>>> <img src="image.php?x=10&y=22">, and the image.php can then add
>>> something at those co-ordinates to demonstrate it has been selected.
>>
>>
>> Thanks, I understand now, I think....
>>
>> Could I just put the imagecopy routine in an external file (called
>> getWorldMap.php, with the getWorldMap() function contained
>> within) and then do:
>>
>> <?php include("getWorldMap.php");
>>
>> $wm = getWorldMap(); // $wm is the resource,copied from WorldMap
>>
>> imagejpg($wm);
>>
>> ?>
>
> You could indeed. That script would output the jpeg, so it has to be on
> its own, and with the correct header sent. I think if you're not going to
> be using the code anywhere else, just keep it in one flat file. That
> would make it a lot easier to comprehend ;)
>
> Also, remember to call imagedestroy() on your image handles to free up the
> memory they use. Otherwise you might find yourself running out of
> resources on your webserver, if its not tidying up after itself.
>
> dave
>
>
Thanks mate.
I've tried it, but the getWorldMap() function doesn't seem to work! I either
get the raw binary data of the jpg
and an error about the header (if I leave the header(...) function in
below), or just the raw data if I leave out the f
function.

This is my file getWorldMap.php
<?php

function getWorldMap()

{

// File and new size

$filename = 'logo_i.JPG';

// Content type

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

// Get new sizes

list($width, $height) = getimagesize($filename);

// Load

$thumb = imagecreatetruecolor($width, $height);

$source = imagecreatefromjpeg($filename);

// Resize

imagecopy($thumb, $source, 0, 0, 0, 0, $width, $height);

// Output

return $thumb;

}

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация