I would like to know if it's possible to convert a image (from any format) to jpeg without writing in disk?
$im = new imagick($url . $image);
$im->setImageFormat('jpg');
$im->writeImage($image .".png");
// I dont want this..I want to use a variable or
// something to get that image in jpeg format.
My point with this is very simple. I have images in JPEG and PNG format. As you know, PNGs are way larger in terms of length used. So, I should convert the images into JPEG and then get the bytes[] of it.
Currently, I'm converting all images (no matter what extension) to bytes[] without any problem. But I would want only to convert images in JPEG, said this, I need to convert the images which aren't JPEG to JPEG.
// My current code to convert to bytes
$url_final = 'C:\\xampp\\htdocs\\MyExample\\image\\' . $image;
// The var $image comes from Database with extension
$fp = fopen($url_final, 'r');
$data = fread($fp, filesize($url_final));
fclose($fp);
$final_data = base64_encode($data);
Could only be the option to doing this, write temporary images files?