set the height and width of binary image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

set the height and width of binary image

Post by manojsemwal1 »

Hi ,

i need a help to set the width and height of binary image. code are like....

<?php

$username = "infosoft_web";
$password = "admin";
$host = "localhost";
$database = "infosoft_webschool";

@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($database) or die("Can not select the database: ".mysql_error());



$query = mysql_query("SELECT * FROM Photo WHERE ID='2'");
$row = mysql_fetch_array($query);
$content = $row['Photo'];
//$size="60000";


header('Content-type: image/jpg');
header("Content-length: $size");
echo $content; /// here image are in full length so how to configure the width and height


Thanks



?>
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: set the height and width of binary image

Post by Darhazer »

If I understand you correctly, you need to know the $size used for the Content-Length parameter?
if so, $size=strlen($content);
if no, why would you need to know the width and height if you are just outputting the image?

By the way I've wrote a script that can parse JPEG headers to determine width and height, I'm going to publish it in the first days of 2011
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: set the height and width of binary image

Post by manojsemwal1 »

thanks for ur quick reply..................

actually the image size (width,height) is too much large. so i want to customize this as per user requirment..................like fix the image width and height....


Thanks
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: set the height and width of binary image

Post by Darhazer »

manojsemwal1 wrote:thanks for ur quick reply..................

actually the image size (width,height) is too much large. so i want to customize this as per user requirment..................like fix the image width and height....


Thanks
Maybe you want to resize the image?
Better do this before saving it to database.
Look at the GD functions, you can use imagecreatefromstring, imagecopyresampled and imagegd to output resized image
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: set the height and width of binary image

Post by manojsemwal1 »

Ya i had tried the written links but not got success.
$query = mysql_query("SELECT * FROM Photo WHERE ID='2'");
$row = mysql_fetch_array($query);
$content = $row['Photo'];


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

//print $content;
imagejpeg($content);

When i use print $content the image is showing but when i use imagejpeg($content); image is not showing...................

may be this due to binary or simple image calling.............?

Pl tell

Thanks
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

How to set the binary image in data form

Post by manojsemwal1 »

How to set the Binary data Image in data form like

I have store image to blob in sql server and want to display in the form of employee information page so how can i do it..........

help

Thanks
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: set the height and width of binary image

Post by Darhazer »

read the manual
imagejpeg works with resource handle, not with binary data

Code: Select all

$image = imagecreatefromstring($content);
// add imagecopyresampled() to resize the image
imagejpeg($content);
Post Reply