1

I am creating various pattern images using js, just like rotate image etc. but now it create blob image url, I need this image in to dataurl, so using input field I will convert it into images using php.

Please check code.

<form method="post" action="process.php">
<input type='file' id='getval' name="background-image" onchange="allcurve(event)"  />

<input type="hidden" name="forearmleft" id="forearm" value="">

<input type="submit" name="submit" id="submit" value="submit">
   <!--<img src="" id="elbotxt">-->
</form>

<canvas id="mr_rotator_can" width="436" height="567"></canvas>



<script type="text/javascript">

function allcurve(event){

forearmleftcurve(event);

        /* left forarms start here*/
        var temp_can1, temp_can1_ctx;

        function forearmleftcurve(event){

            var getImagePath = URL.createObjectURL(event.target.files[0]);
                console.log(getImagePath)

            temp_can1 = document.getElementById('f6258182013');
            temp_can1_ctx = temp_can1.getContext('2d');

            forearmleftrotator(getImagePath, '77');


        };

        function forearmleftrotator(var2, var3) 
                {
            var mr_rotator_var = document.getElementById('mr_rotator_can');
            var mr_rotator_var_ctx = mr_rotator_var.getContext("2d");
            mr_rotator_var.width = mr_rotator_var.width;
            var imageObj_rotator = new Image();

            imageObj_rotator.onload = function () {
                var pattern_rotator = mr_rotator_var_ctx.createPattern(imageObj_rotator, "repeat");
                mr_rotator_var_ctx.fillStyle = pattern_rotator;
                mr_rotator_var_ctx.rect(0, 0, mr_rotator_var.width, mr_rotator_var.height);
                mr_rotator_var_ctx.rotate(var3 * Math.PI / 180);
                mr_rotator_var_ctx.fill();

            };
            imageObj_rotator.src = var2;            


            $('#forearm').attr("value", var2);          


        }


}
 </script>
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • and wheres the error? – Jonas Wilms May 08 '17 at 14:04
  • I want to convert var2 in to dataurl, and it will pass in field so i will submit and convert that data url to image using file_put_contents(), so how can i convert it. – user3564428 May 08 '17 at 14:21
  • `$('#forearm').attr("value", mr_rotator_var.toDataURL())` But you'd even win by sending a Blob version : http://stackoverflow.com/questions/34711715/phpjs-how-to-do-fileuploads-in-html-form-as-content-type-multipart-via-js/34713226#34713226 – Kaiido May 08 '17 at 15:06
  • it is returning data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbQAAAI3CAYAAADz+K6tAAAD1UlEQVR4nO3BAQEAAACCIP+vbkhAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMCdARnIAAFVdnt/AAAAAElFTkSuQmCC and show blank image – user3564428 May 08 '17 at 15:20
  • because you need tto cal it in your images onload. – Kaiido May 09 '17 at 00:50
  • Please help me through snippet code, I am not getting how to achieve that. – user3564428 May 09 '17 at 04:52

0 Answers0