Jump to content


Photo

how to process an image from the IMG tag before displaying


  • Please log in to reply
2 replies to this topic

#1 anne13

anne13
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 April 2006 - 03:12 AM

Hi All!

I have a java servlet class that is needed to be coded in PHP.

I need to process the image coming from the REQUEST of an IMG tag.


HTML Code example:
IMG="http://a.abc-efg.co.jp/demo/Sample.jpg"

From this URL, a request comes in for the Sample.jpg to be displayed. But before this image be displayed, some process should be done first at the back-end, then the right size of the image should will be displayed.

A php script will not be called from this IMG tag. The trigger would be the REQUEST..

I have done this in java by using a Filter class and filter mapping in the web.xml file.

I not am sure this can be done in PHP. Please give me some suggestions or code snippets or any tutorial.

Thanks.

#2 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 04 April 2006 - 12:22 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]From this URL, a request comes in for the Sample.jpg to be displayed. But before this image be displayed, some process should be done first at the back-end, then the right size of the image should will be displayed.[/quote]

so Im assuming you want an image resize script, well here's one that works well
<?php
$img = $_REQUEST['<image name>'];

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

$source = imagecreatefromjpeg($img);
$width = imagesx($source);
$height = imagesy($source);
$max = <maximum size> // ie 250, if max size is 250x250
if(($width > $max) || ($height > $max))
    {if($width > $height)
        {$new = ($width/$max);}
    else
        {$new = ($height/$max);}
    $new_width = ($width/$new);
    $new_height = ($height/$new);
    
    $new_image = imagecreatetruecolor($new_width, $new_height);
    
    imagecopyresized($new_image, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
    imagejpeg($new_image);
    }    
else
    {imagejpeg($source);}
?>

got a problem? Google helps many of those in need

#3 anne13

anne13
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 April 2006 - 02:28 AM

Thanks for your reply.

Actually, the image I want to display are already resized using ImageMagick. The part that I don't know how to do is, "knowing that an IMG request has come from the IMG tag".

Because in the client side code[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]
IMG="http://a.abc-efg.co.jp/demo/Sample.jpg"
[!--colorc--][/span][!--/colorc--], there is no PHP page being called.. The REQUEST will come to this [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]/demo/[!--colorc--][/span][!--/colorc--] folder under the document root. How do I handle requests coming to this folder? I want to call a PHP script when this (IMG="http://a.abc-efg.co.jp/demo/Sample.jpg) kind of requests comes in..

Hope my explanation is not bad...






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users