Reply to Re: Inserting modified image into a database

Re: Inserting modified image into a database new!
by colin, 15 years, 9 months ago
What about something like this?

include('class.upload.php');
$foo = new upload($_FILES['form_field']);
if ($foo->uploaded) {
  // Your first pass at the image
  $foo->image_convert         = 'png';
  $foo->image_resize          = true;
  $foo->image_x               = 500;
  $foo->image_ratio_y         = true;
  // Call process() without an argument to get the image in return
  $img = $foo->process();
  // File WAS processed successfully.
  if ($foo->processed) {
    // Prepare the query (and then run it). The content of the image is in $img
    $query = " INSERT INTO my_table(image_file) VALUES ('" . addslashes($img) . "')";
    // Store the picture on file, using PHP functions
    imagepng($img, '/home/a/b/c/image.png');
    // Do not delete the temp file as we will do another pass
  }
  // Your second pass at the image (thumbnail)
  $foo->image_convert         = 'png';
  $foo->image_resize          = true;
  $foo->image_x               = 100;
  $foo->image_ratio_y         = true;
  // Call process() without an argument to get the image in return
  $img = $foo->process();
  // File WAS processed successfully.
  if ($foo->processed) {
    // Prepare the query (and then run it). The content of the image is in $img
    $query = " INSERT INTO my_table(thumbnail_file) VALUES ('" . addslashes($img) . "')";
    // Store the picture on file, using PHP functions
    imagepng($img, '/home/a/b/c/thumbnail.png');
    // Delete the temporary file(s).
    $foo->clean();
  }
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important