How to Resize an Image from Database or File Using Php

This implementation is done using php.

Usually we resize image that we read from a local file, then save it locally.
Flow:
1.) read from local image file and store in a php variable
2.) resize the image file using php functionalities
3.) save the image file locally

Now what if we want to read an image file stored in a database then save it locally in a disk.
Here we will use the class from this url:
http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
$resizeObj = new resize();

if(isFile($file)) { //load as file
  $resizeObj -> setFileName($newFileName);
} else { //load as binary string, read from database
  $resizeObj -> setBinaryString($content);
}

$resizeObj -> resizeImage($width, $height);
$resizeObj -> saveImage("resized-".$newFileName);

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source
Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.