riad
riad

Reputation: 7194

Showing resized image on browser

My PHP code below shows an image on browser as its original size 300x300.

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

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

Upvotes: 0

Views: 4437

Answers (5)

Adnan
Adnan

Reputation: 2031

Just make a copy of the image and resize it.

Upvotes: 0

scunliffe
scunliffe

Reputation: 63646

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.

Upvotes: 3

pts
pts

Reputation: 87341

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.

Upvotes: 1

Adrian Mester
Adrian Mester

Reputation: 2533

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?

Upvotes: 5

Joey
Joey

Reputation: 354734

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.

Upvotes: 1

Related Questions