Note that there are some explanatory texts on larger screens.

plurals
  1. POSave image with all kind of extension
    primarykey
    data
    text
    <p>I am using <code>jcrop</code> in my Wordpress project. I was wondering how to save the image with its original extension. Like my code only works for <code>jpg</code> image. I am saving the cropped image to server. Here is my PHP code:</p> <pre><code>if(isset($_POST['saveCrop'])) { $targ_w = $targ_h = 150; $jpeg_quality = 90; $src = plugins_url( "employee/uploads/".$_POST['imgName'] , dirname(__FILE__) ); $img_r = imagecreatefromjpeg($src); $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); header('Content-type: image/jpeg'); @imagejpeg($dst_r, $_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/employee/uploads/".$_POST['imgName'], $jpeg_quality); //imagejpeg($dst_r,null,$jpeg_quality); } </code></pre> <p>If I try with <code>png</code> image, I get a black one. Same thing happens for <code>gif</code>. How can I get it to work with all extensions and save with its original extension (jpg for jpg, png for png). <strong>Update::</strong> *<em>ok.. for creating png file i was trying this code. I am sure i am doing something wrong:</em>*</p> <pre><code>$img_r = imagecreatefrompng($src); $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); header('Content-type: image/png'); @imagepng($dst_r, $_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/employee/uploads/".$_POST['imgName'], $jpeg_quality); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload