2

我参考了这个网址

我正在使用croppie 插件,它在Android、Chrome、Mozilla 上运行良好。但不适用于 iOS 和 Safari。如果我从 iOS 上传了一张图片,那么它会旋转 90*。此外,图像未在 Safari 上上传。这是我的完整代码,

HTML

<div class="container">
    <div class="panel panel-default">
      <div class="panel-heading">Image Upluad</div>
      <div class="panel-body">
        <div class="row">
            <div class="col-md-4 text-center">
                <div id="upload-demo" style="width:350px"></div>
            </div>
            <div class="col-md-4" style="padding-top:30px;">
                <strong>Select Image:</strong>
                <br/>
                <input type="file" id="upload">
                <br/>
                <button class="btn btn-success upload-result">Upload Image</button>
            </div>
            <div class="col-md-4" style="">
                <div id="upload-demo-i" style="background:#e1e1e1;width:300px;padding:30px;height:300px;margin-top:30px"></div>
            </div>
        </div>
      </div>
    </div>
</div>

JS

<script type="text/javascript">
$uploadCrop = $('#upload-demo').croppie({
    enableExif: true,
    viewport: {
        width: 200,
        height: 200,
        type: 'circle'
    },
    boundary: {
        width: 300,
        height: 300
    }
});
$('#upload').on('change', function () { 
    var reader = new FileReader();
    reader.onload = function (e) {
        $uploadCrop.croppie('bind', {
            url: e.target.result
        }).then(function(){
            console.log('jQuery bind complete');
        });
    }
    reader.readAsDataURL(this.files[0]);
});
$('.upload-result').on('click', function (ev) {
    $uploadCrop.croppie('result', {
        type: 'canvas',
        size: 'viewport'
    }).then(function (resp) {
        $.ajax({
            url: "/ajaxpro.php",
            type: "POST",
            data: {"image":resp},
            success: function (data) {
                html = '<img src="' + resp + '" />';
                $("#upload-demo-i").html(html);
            }
        });
    });
});
</script>

ajaxpro.php

$data = $_POST['image']; list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data); $data = base64_decode($data);
$imageName = time().'.png'; file_put_contents('upload/'.$imageName, $data);
echo 'done';

请帮我修复。

4

1 回答 1

3

我找到了解决方案。

enableExif需要文档中所述的 exif.js:http: //foliotek.github.io/Croppie/#enableExif

添加后它在所有设备上都可以正常工作。

于 2018-02-21T06:24:54.657 回答