Hi,
hope you can help me. I am working with a database (mysql) already created, pictures were stored in a longblob field, but this is the only field related to pictures (so I have no info about their size).
I manage to extract and display the pictures - using a php file like this: poza.php

<?php
ob_start();
ob_clean();
include'conn.php';//connects to server and select db
if (IsSet($_GET['imgid'])){ //imgid is the id of the row	
$img_id =$_GET['imgid'];
$query = "SELECT * FROM angajati_eurotire WHERE id_ae=$img_id";
$result = mysql_query($query); 
header("content-type: image/jpeg");	
while ($row = mysql_fetch_array($result)) 
{ print $row[poza]; } //poza is the column where images are stored
mysql_free_result($result); 	
}
ob_end_flush();
?>

Then I display the picture using <img src="poza.php?imgid=[ID]">.
This works ok, but I need to display this pictures as thumbnails (about 30% of their actual size). The pictures have random sizes.
Is there any way I can determine the image size?
Or maybe I'm going on a wrong track with all this?
Thanks for your time.
Ina

Recommended Answers

All 3 Replies

I am guessing the below code might work but I am not sure as you are reading from a variable and not a file. So try the following and if it does not work, you will need to use something simular but use the gd library/binary to allow the

list($width, $height, $type, $attr) = getimagesize($row[poza]);

The above code theoratically stores the width and height in the variables $width and $height which you can call after that line has been executed/ran. If you are wondering where to place it, place it after the below couple of lines:

while ($row = mysql_fetch_array($result))
{ print $row[poza]; }

As I said it might not work and might need some sort of conversion but it's worth a try as that is in the official documentation.

Thank you for your answer, but unfortunately I already tried getimagesize(); it is not working here (I use it in other pages, where I have the pictures stored in a folder on the server and I only have their address stored in the database).
Maybe there is another way to use the blob field?
The way I did it it only publish the picture...
Thanks anyway,
Ina

I used this:

$image_data=trim($ra[poza]);

$a=imagecreatefromstring($image_data);
$wo = imagesx($a);//width
$ho = imagesy($a);//height

then i used these values to display the picture at any maximum w and h, constraining proportions
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.