resizing an image.
am 02.04.2008 01:02:53 von AmitHi group,
What is the best way to rersize an image to a specific width and
height?
Any samples?
Thanks.
Hi group,
What is the best way to rersize an image to a specific width and
height?
Any samples?
Thanks.
On Apr 1, 4:02=A0pm, amit
> Hi group,
>
> What is the best way to rersize an image to a specific width and
> height?
>
> Any samples?
>
> Thanks.
Just to explain my case:
Currently I have a png file. it will be uploaded and then converted to
JPEG file. Either before conversion or after conversion (which is
better?) I need to change the size of it to be width=3D320 pixcel and
height =3D240 pixcel
Thanks.
On Apr 1, 4:19=A0pm, amit
> On Apr 1, 4:02=A0pm, amit
>
> > Hi group,
>
> > What is the best way to rersize an image to a specific width and
> > height?
>
> > Any samples?
>
> > Thanks.
>
> Just to explain my case:
>
> Currently I have a png file. it will be uploaded and then converted to
> JPEG file. Either before conversion or after conversion (which is
> better?) I need to change the size of it to be width=3D320 pixcel and
> height =3D240 pixcel
>
> Thanks.
This is currently what I'm doing:
$tmp =3D imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($dst, $file, 0,0,0,0, $new_width, $new_height, 320,
240);
imagejpeg($tmp, "/var/www/html/apps/sa/usr_bg_imgs/" . "newfile.png",
100);
However, generated image is a black image only!
<57d37985-0849-4530-8d59-9c51ba5f6f16@s8g2000prg.googlegroups.com>
> What is the best way to rersize an image to a specific width and
> height?
>
> Any samples?
>
The code below doesnt mind if the source image is widescreen or portrait
as it will resize either to suit .
$max_width=150;
$max_height=107;
$source="demo/blah.jpg";
$thumb=imagecreatetruecolor($max_width,$max_height);
$grab=imagecreatefromjpeg($source);
$dummy="#FAF9EC"; include('colour_convert.php'); $kol=imagecolorallocate
($thumb,$grab1,$grab2,$grab3);
imagefilledrectangle($thumb,0,0,$max_width,$max_height,$kol) ;
$size=GetImageSize($source);
$width_ratio=($size[0]/$max_width);
$height_ratio=($size[1]/$max_height);
if ($width_ratio>=$height_ratio)
{$ratio=$width_ratio;}
else
{$ratio=$height_ratio;}
$new_width=($size[0]/$ratio);
$new_height=($size[1]/$ratio);
$glasgow=0; if ($new_width<$max_width) {$glasgow=75-$new_width/2;}
$paisley=0; if ($new_height<$max_height) {$paisley=54-$new_height/2;}
imagecopyresampled($thumb,$grab,$glasgow,$paisley,0,0,$new_w idth,
$new_height,$size[0],$size[1]);
colour_convert.php being the following .....
$temp=str_replace("#","",$dummy); $temp=strtoupper($temp);
$temp1=substr($temp,0,2);
$temp2=substr($temp,2,2);
$temp3=substr($temp,4,2);
$grab1=hexdec($temp1);
$grab2=hexdec($temp2);
$grab3=hexdec($temp3);
?>
Hardly stunning code - but it works fine and i've more important things
to do than tinker around rewiting it .
--
www.krustov.co.uk
> imagecopyresampled($thumb,$grab,$glasgow,$paisley,0,0,$new_w idth,
> $new_height,$size[0],$size[1]);
>
$jenny="poop/whatever.jpg";
imagejpeg($thumb,$jenny,70); imagedestroy($thumb); imagedestroy($grab);
Add the above code that i snipped by mistake .
On Apr 1, 5:04=A0pm, Krustov
>
>
>
>
>
> > imagecopyresampled($thumb,$grab,$glasgow,$paisley,0,0,$new_w idth,
> > $new_height,$size[0],$size[1]);
>
> $jenny=3D"poop/whatever.jpg";
>
> imagejpeg($thumb,$jenny,70); imagedestroy($thumb); imagedestroy($grab);
>
> Add the above code that i snipped by mistake .
Thank you but it is so confusing the way it is written in terms of
variable names. Also, I get so many division by zero.
However, I will do something about it.
Thanks for your time.