tags:

views:

353

answers:

5

Dear all, My below PHP code show a image on browser as its original size 300x300.

<?

$location="http://localhost/folwer.bmp ";   
header("Location:  $location");

?>

But I need to show it 120x240 or any other size on browser. How can i do it without resize the original image using PHP? Pls help.

+1  A: 

As long as you hand the browser only the image you can't control this. You can wrap it in a simple HTML file and set the width and height attributes on the <img> tag, though.

If you're using this to display the image in a web page already then you can just alter the <img> tag there.

Joey
its not working could u pls help me bro.$location="http://localhost/folwer.bmp "; header("Location: <img src="$location" width="200" height="85">");
riad
+2  A: 

Replace your script with this:

<?php
$location = '/flower.bmp';
echo '<img src="'.htmlspecialchars($location).'" width="120" height="240">';

This generates a HTML page with the proper image tag, which loads flower.bmp at the proper size.

pts
thanks for your answer.But the localtion is dynamic here and its through a URL.So must need to use a variable here is $location and must need to use the header function.How i can use the variable in header function...thanks..pls help
riad
@riad: Adding pls help to everything you write is not gonna help. Please stop it. That being said, I edited pts's answer.@pts I hope you don't mind, feel free to revert otherwise.
phihag
+2  A: 

use the class on this page (save it as SimpleImage.php on your server) then use this:

<?php
   header('Content-Type: image/jpeg');
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load($location);
   $image->resize(120, 240);
   $image->output();
?>

A few comments:

For this to work, the $location variable has to have the path of the image on your server, not the URL.

This will resize the image to 120 pixels in width and 240 in height. You probably want 240 x120.

I'm not sure if this works with bmp files. What are you doing working with bmp files anyway?

Adrian Mester
Thanks bro for your ans.File type is not mendatory here.But the output url need to through using header function.
riad
+2  A: 

Side note: You will want to change your image to a PNG, JPG, or GIF as BMP is not a fully supported web browser image format.

scunliffe
A: 

Just make a copy of the image and resize it.

adnan