-2

UPDATE: now I learned more I looked alot and modified I got this:

function show_image($image, $new_width, $new_height) {
    //$this->helper('file');                   why need this?
    //$image_content = read_file($image);      We does not want to use this as output.
    list($old_width,$old_height) = getimagesize("$image");
    //resize image
    $image = imagecreatefromjpeg($image);
    $thumbImage = imagecreatetruecolor($new_width, $new_height);
    imagecopyresized($thumbImage, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
    imagedestroy($image);
    //imagedestroy($thumbImage); do not destroy before display :)
    ob_end_clean();  // clean the output buffer ... if turned on.
    header('Content-Type: image/jpeg');
    imagejpeg($thumbImage); //you does not want to save.. just display
    imagedestroy($thumbImage); //but not needed, cause the script exit in next line and free the used memory
    exit;

} when using this function I get a file, but I need to get a URL I wanna be able to use:

 <img src=" ... ">
  • I'm assuming these are user-uploaded images? And that you want a small and a full resolution version of each? – Harvtronix Feb 28 '15 at 01:42
  • yes exactly, I want to show 300*150 of the picture – Sif Eddine Belalia Feb 28 '15 at 01:47
  • Did you try **Google**? http://www.codeforest.net/upload-crop-and-resize-images-with-php – MiChAeLoKGB Feb 28 '15 at 01:53
  • @MiChAeLoKGB I believe the image manipulator library included in the link you posted relies on GD, which is not available on the server in question. – Harvtronix Feb 28 '15 at 02:01
  • @Harvtronix If he cant use GD, Imagick or Gmagick, then he is screwed. You can use jQuery etc. for client side cropping, but for saving them on server? Thats problematic without any of that. If he can use one of that, then http://imagine.readthedocs.org/en/latest/ – MiChAeLoKGB Feb 28 '15 at 02:06
  • The canvas toDataUrl function will give base64 encoded data of the image. This should be easily decoded in php and written to a file – Harvtronix Feb 28 '15 at 02:12

1 Answers1

0

Since you can't use GD on the server, a good option might be to handle it on the client side.

One idea that comes to mind is loading the image into an html5 canvas, and using that to manipulate the image characteristics before uploading it to the server.

This post talks about how you'd go about uploading image data straight from a canvas and saving it as an image on your server.

How to save a HTML5 Canvas as an image on a server

You also will likely need to take a look at the JavaScript File API to load the image into the canvas on the client side.

It's not necessarily an easy solution, but it might be your best shot without access to GD and stuff.

Community
  • 1
  • 1
Harvtronix
  • 854
  • 6
  • 16