I'm using SimpleImage
to resize images in PHP. I need to resize the images uploaded via a form using the file browse. I use the following approach to resize the image uploaded via a file browse.
$image=new SimpleImage();
$image->load($_FILES['txt_brand_img']['tmp_name']); //It isn't working.
if($image->getWidth()>500)
{
$image->resizeToWidth(500);
$image->save("images_db/".$filename);
}
It isn't working. I could see somewhat resemble approach here but it didn't work for me. When I upload and save the image in a directory and give the saved file path to the load()
function as follows it is working.
$filename=rand(1000,1000000).$_FILES["txt_brand_img"]["name"];
move_uploaded_file($_FILES["txt_brand_img"]["tmp_name"],"images_db/".$filename);
$image=new SimpleImage();
$image->load("images_db/".$filename); //It is working.
if($image->getHeight()>100 || $image->getWidth()>100)
{
$image->resize(100, 100);
$image->save("images_db/thumb/".$filename);
}
else
{
$image->save("images_db/thumb/".$filename);
}
May I be using a wrong approach in the previous code snippet? How could the uploaded images be directly resized without saving them using SimpleImage
?