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