Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery('.modal-footer .capture').click(function(){
- var target = jQuery('#manipulated-img')
- html2canvas(target, {
- onrendered: function(canvas) {
- var img = canvas.toDataURL()
- jQuery.ajax({
- data: {'action': 'store-img', 'img' : img},
- type: 'POST',
- url: ajaxurl,
- success:function(ret){
- jQuery('.product-addon-manipulated-image > p > input').val(ret)
- jQuery('#myModal').fadeOut()
- }
- })
- }
- });
- })
- public function store_img() {
- //just a random name for the image file
- $random = md5( uniqid( mt_rand(), true ) );
- //convert the binary to image using file_put_contents
- $dir = wp_upload_dir()['basedir'] . '/add-on';
- if ( ! file_exists( $dir ) ) {
- wp_mkdir_p( $dir );
- }
- $savefile = @file_put_contents( $dir . "/$random.png", base64_decode( explode( ",", $_POST['img'] )[1] ) );
- //if the file saved properly, print the file name
- if( $savefile ){
- echo wp_upload_dir()['baseurl'] . "/add-on/$random.png";
- } else{
- echo "failed";
- }
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement