1
I have an image saved in BD need to know how to Resize it, how to save it in a folder.
1
I have an image saved in BD need to know how to Resize it, how to save it in a folder.
1
RESOLVED
//Seta endereço da Imagem
$src = './thumbnail/'.$objeto->id.'.jpg';
//VERIFICA SE ARQUIVO THUMBNAIL JA EXISTE
//E Verifica se ARRAY DE BYTES QUE VEM DO BD é nulo
if(!file_exists($src) && $objeto->foto!=null){
$arquivo = fopen($src,'wb');
//Salva foto original
fwrite($arquivo, $objeto->foto);
fclose($arquivo);
//Carrega foto Original
$img = WideImage::load($src);
//Redimensiona imagem, usando parametro inside não destorce a imagem
$img = $img->resize(100,100,'inside');
//Salva foto com qualidade 80%
$img->saveToFile($src,80);
}
//MOSTRAR IMAGEM
if(file_exists($src)) //verifica se imagem existe, pode ser que não exista foto no BD no entanto é preciso tratar quando nao houver pois não será criado nenhum arquivo
echo "<img src='$src'/>";
else
echo "<img src='./thumbnail/default.jpg'/>";
Note: Function load of Wideimage can receive binary but I could not make it work doing this $img = Wideimage::load($object->photo);
Thanks to @Maniero who helped me save file How to save byte array in PHP file?
Using Wideimage?
Yes, Wideimage. But I’m testing the Canvas class.
It’s worth taking a look at Intervention Image as well. It’s pretty simple to use https://github.com/Intervention/image
Browser other questions tagged php image
You are not signed in. Login or sign up in order to post.
The save part has already been asked in http://answall.com/questions/47101/como-salvar-array-de-bytes-em-arquivo-no-php, so this part is duplicated.
– Maniero
A word : The function imagecopyresized. Then just use the function that loads the image from a string
– Wallace Maxters
@bigown rephrased the most complete question as he was advised to do so. Now it’s settled sorry for the confusion. Thank you
– Skywalker