Image creating in PHP/Javascript giving a grey output around the image -
Here's the link and to see what I'm saying.
Demo:
If I try to crop the image a lot, then this is the right size and correct image Will produce, but you can see the color around it.
I do not know how to change it, here it is save.php '
which is said in Javascript:
& lt; Php if ($ _ server ['REQUEST_METHOD'] == "POST") {// Image name $ name = sha1 (uniqid (mt_rand (), true)); // url = 'temp /' to save the crop image to the location $ Name '. Jpg '; $ Dst_x = 0; $ Dst_y = 0; $ Src_x = $ _POST ['x']; // Crop Start x $ src_y = $ _POST ['y']; // Crop Srart y $ src_w = $ _POST ['w']; // $ src_x + $ dst_w $ src_h = $ _POST ['H']; // $ src_y + $ dst_h // has set a specific size for the image / default to get the width and height from the crossed image is $ Dst_w = 240; $ Dst_h = 240; // base64 part $ base64 = $ _POST ['image']; // If the URL is a base 64 string (if substrate ($ base64, 0, 5) == 'data:') {// image $ base64 = preg_replace ('# data: image / [^;] +; base 64, # ',' ', basebase basin); $ Base64 = base64_decode ($ base64); // Create an image from string $ source = imagecreatefromstring ($ base64); } Strip parameter base64 = strtok ($ base64, '?') Depending on other {// URL}; List ($ height, $ width, $ type) = getimagesize ($ base64); // Create Image ($ type == 1) $ source = imagecreatefromgif ($ base64); And if ($ type == 2) $ source = imagecreatefromjpeg ($ base64); And if ($ type == 3) {$ source = imagecreatefrompng ($ base64); // Keeping transparent background // imagealphobalending ($ image, wrong); // imaisivlfa ($ image, true); } And die (); } $ Image = imagecreatetruecolor ($ dst_w, $ dst_h); Imagecopyresampled ($ image, $ source, $ dst_x, $ dst_y, $ src_x, $ src_y, $ dst_w, $ dst_h, $ src_w, $ src_h); $ White = imagecolorallocate ($ image, 255, 255, 255); Image file ($ image, 0, 0, white $); // Save image imagejpeg ($ image, $ url, 100); // Return URL $ validation = array ('url' = & gt; $ url); Echo json_encode ($ validation); }
I have to be white only around it, this is gray matter how can I do this
You need to fill the copy-resampling image before:
$ image = imagecreatetruecolor ($ dst_w, $ dst_h); $ White = imagecolorallocate ($ image, 255, 255, 255); Image file ($ image, 0, 0, white $); Imagecopyresampled ($ image, $ source, $ dst_x, $ dst_y, $ src_x, $ src_y, $ dst_w, $ dst_h, $ src_w, $ src_h);
I also see that javascript is passing invalid x, y, w, and h parameter to the size of the image used by PHP scripts. For example, I tried the page and the following post parameters were sent:
X = -297.61904761904765 and y = -297.61904761904765 and w = 595.2380952380953 and HK = 595.2380952380953
Because the input The image is 250 × 500, 595 or too large for $ src_w
or $ src_h
. Negative numbers also do not understand, either.
Comments
Post a Comment