Re: [PHP] resize image and store it to DB

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 5:54 am, Alain Roger wrote:
 else // both $width and $height are smaller than max, so we need to
 zoom

Zooming an image is RARELY satisfactory in appearance...

I'd say just leave it alone, personally.

 $escaped = pg_escape_bytea($thumb); // does not work and it's normal

 $thumb is an image, so ho can i make it useful for pg_escape_bytea
 function
 ?

$thumb isn't the actual JPEG image.

It's just a PHP resource number, pointing to the image.

So, essentially, you are cramming the number 3 (or 2 or 4 or
whatever) into PostgreSQL.

You would need to do something not unlike:

ob_start();
imagejpeg($thumb);
$image = ob_get_contents();
ob_end_clean();
$escaped = pg_escape_bytea($image);

//Insert obligatory don't store images in DB flame-war here :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] resize image and store it to DB

2007-05-01 Thread Alain Roger

Hi,

I allow web application users to insert their own picture into database.
but i defined a max size limit 130 px width by 160px height.

so for that i determine the max ratio in case of picture does not have this
size.
after that i resize it and would like to store it to DB, however i have some
problem once it is resized.

here is my code :


data = file_get_contents($_FILES['uploadedfile']['tmp_name']);

$img = imagecreatefromstring($data);
$width = imagesx($img);
$height = imagesy($img);

$maxwidth = 130; //130px
$maxheight = 160; //160px

$ratio =0.00;
if($width $maxwidth || $height$maxheight)// image is somehow
bigger than 160px * 130px
{
 if($width $maxwidth)
 {
  $ratio = $maxwidth/$width;
 }
 if($height$maxheight)
 {
  // always take the smallest ratio
  $ratio = ($maxheight/$height)  $ratio ? $ratio : ($maxheight/$height);
 }
}
else // both $width and $height are smaller than max, so we need to zoom
{
 $i=0.00;
 $i=($maxwidth/$width);
 $i = ($maxheight/$height)  $i ? $i : ($maxheight/$height);
 $ratio = $i;
}

$newwidth = $width*$ratio;
$newheight = $height*$ratio;
$thumb = imagecreatetruecolor($newwidth, $newheight);

imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width,
$height);

$escaped = pg_escape_bytea($thumb); // does not work and it's normal



$thumb is an image, so ho can i make it useful for pg_escape_bytea function
?

i do not want to create a tmp file on server and after load it.
I would like to do it stored image directly into DB on-fly.

thanks alot,
--
Alain

Windows XP SP2
PostgreSQL 8.1.4
Apache 2.0.58
PHP 5


Re: [PHP] resize image and store it to DB

2007-05-01 Thread Tijnema !

On 5/1/07, Alain Roger [EMAIL PROTECTED] wrote:

Hi,

I allow web application users to insert their own picture into database.
but i defined a max size limit 130 px width by 160px height.

so for that i determine the max ratio in case of picture does not have this
size.
after that i resize it and would like to store it to DB, however i have some
problem once it is resized.

here is my code :

 data = file_get_contents($_FILES['uploadedfile']['tmp_name']);

 $img = imagecreatefromstring($data);
 $width = imagesx($img);
 $height = imagesy($img);

 $maxwidth = 130; //130px
 $maxheight = 160; //160px

 $ratio =0.00;
 if($width $maxwidth || $height$maxheight)// image is somehow
 bigger than 160px * 130px
 {
  if($width $maxwidth)
  {
   $ratio = $maxwidth/$width;
  }
  if($height$maxheight)
  {
   // always take the smallest ratio
   $ratio = ($maxheight/$height)  $ratio ? $ratio : ($maxheight/$height);
  }
 }
 else // both $width and $height are smaller than max, so we need to zoom
 {
  $i=0.00;
  $i=($maxwidth/$width);
  $i = ($maxheight/$height)  $i ? $i : ($maxheight/$height);
  $ratio = $i;
 }

 $newwidth = $width*$ratio;
 $newheight = $height*$ratio;
 $thumb = imagecreatetruecolor($newwidth, $newheight);

 imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width,
 $height);

 $escaped = pg_escape_bytea($thumb); // does not work and it's normal


$thumb is an image, so ho can i make it useful for pg_escape_bytea function
?

i do not want to create a tmp file on server and after load it.
I would like to do it stored image directly into DB on-fly.

thanks alot,
--
Alain



I don't know if there's a better way, but you could try output
buffering, so that you start it, output the image with imagejpeg,
imagepng, imagegif, etc. and then get the contents of the buffer.

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] resize image and store it to DB

2007-05-01 Thread Robert Cummings
On Tue, 2007-05-01 at 12:59 +0200, Tijnema ! wrote:
 
 I don't know if there's a better way, but you could try output
 buffering, so that you start it, output the image with imagejpeg,
 imagepng, imagegif, etc. and then get the contents of the buffer.

That's what I'd suggest also... since it's what I do :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] resize image and store it to DB

2007-05-01 Thread tedd

At 12:54 PM +0200 5/1/07, Alain Roger wrote:


i do not want to create a tmp file on server and after load it.
I would like to do it stored image directly into DB on-fly.


Why?

My understanding is that when you upload a file, it has to go 
somewhere. It might as well go into a tmp folder/file that php 
handles (creates/deletes), right? Or is this something that can be 
handled totally within memory? And if so, what's the difference, 
speed, security, what?


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] resize image and store it to DB

2007-05-01 Thread Robert Cummings
On Tue, 2007-05-01 at 11:08 -0400, tedd wrote:
 At 12:54 PM +0200 5/1/07, Alain Roger wrote:
 
 i do not want to create a tmp file on server and after load it.
 I would like to do it stored image directly into DB on-fly.
 
 Why?
 
 My understanding is that when you upload a file, it has to go 
 somewhere. It might as well go into a tmp folder/file that php 
 handles (creates/deletes), right? Or is this something that can be 
 handled totally within memory? And if so, what's the difference, 
 speed, security, what?

If you're going to put it in a database, then there's no sense incurring
the filesystem overhead of a temporary file. It can indeed be done
completely in memory by using output buffering.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php