Forum Moderators: coopster

Message Too Old, No Replies

PHP java applet

need help with displaying image in applet

         

Kyle2911

10:36 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Hey all,

I'm a real beginner when it comes to PHP, so please bare with me.

I'm using a Java Applet to display an image:

<applet code="PoolMenu" width="272" height="432" align="top">
<param name="url" value="getimage.php">

My getimage.php file looks like:

<?php
header('Content-Type: image/jpeg');
readfile($image_name.jpg); //Path to image
?>

But the image is not displaying.

What is it that I am doing wrong in the "value" section of the applet?

I basically want to hide the URL of the image with PHP in the applet.

Any help or other ideas would be appreciated

Cheers!

phpmattk

4:51 am on Aug 9, 2005 (gmt 0)

10+ Year Member



Anything displayed after the line :

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

Has be outputting a jpeg, readfile doesn't return a jpeg, it will probably be returning a jumbled string that is your jpeg, you should be using the GD library and the imageJPEG function. Its slightly detailed, I'd recommend searching for "php imageJPEG" and reading up on that, and possibly skimming the GD section of the PHP Manual.

Try pasting this into your script, that should get you started. instead of filling it with color though, you'd want to load a jpg from a file.

<?
Header ("Content-type: image/png");

$image = imagecreate(100, 100);

$black = imageColorAllocate($image, 0, 0, 0); // allocate color black
$blue = ImageColorAllocate ($im, 0, 0, 255);

// imagefill is optional since the image will automatically be created with the first
// color allocated: black. The fill covers up the black and makes the image blue.
// imageFill($image, 0, 0, 50, 50, $blue); // use it for drawing

ImagePng ($image);

// destroy the image to free memory

ImageDestroy ($image);
?>

coopster

12:17 pm on Aug 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually, you don't need to go through those steps, phpmattk. Sending out that 'Content-Type' and then forcing the file stream out to the browser will suffice. Have a look at this thread regarding "How to convert image blob files back to image [webmasterworld.com]" for some details (concerns reading from a database, but the same concept holds true when reading from the filesystem).

Welcome to WebmasterWorld, Kyle2911.

I think your issue may actually lie in this line of your php script:

readfile($image_name.jpg); //Path to image

Are you certain that is what you want there? It seems perhaps you want something along the lines of

readfile("$image_name".'.jpg'); //Path to image

You could always build a variable first and then dump it to your browser to see if it is indeed the path to the image, exactly as you expect it to be.