Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery cropit export method return only 'data:,' string

Tags:

html

jquery

crop

my html code for cropit:

<div id="image-cropper" style="direction: ltr">
    <div class="row margin-top-25">
        <div class="col-md-8 col-md-offset-2">
            <div class="cropit-image-preview-container">
                <div class="cropit-image-preview"></div>
            </div>
        </div>
    </div>
    <div class="row margin-top-15">
        <div class="col-md-4 col-md-offset-4">
            <input type="range" class="cropit-image-zoom-input" />
        </div>
    </div>
    <div class="row margin-top-15">
        <div class="col-md-4 col-md-offset-4">
            <input type="file" style="display: none" class="cropit-image-input" />
            <div class="R_butt_blue choose_pic text-center">انتخاب تصویر</div>
        </div>
    </div>

</div>

and my javascript code for cropit:

$('.choose_pic').click(function(){
     $('.cropit-image-input').click();
});

var z = $('#image-cropper').cropit({
    exportZoom: 1,
    imageBackground: true,
    imageBackgroundBorderWidth: 15 // Width of background border
});
$('.send_image').click(function(){
    var h = z.cropit('export');
    $('#photo_show img').attr({ src: h });
});

I want to crop a image by using cropit jquery plugin, i read full document and multi example on web, but that return only a string that contain data:, i dont know what is wrong?

like image 541
omid nematollahi Avatar asked Sep 29 '22 04:09

omid nematollahi


1 Answers

You should define the .cropit-image-preview css class in order to set the width and the height of cropped image.

.cropit-image-preview {
  /* You can specify preview size in CSS */
  width: 100px;
  height: 100px;
}

and also use the selector like this:

var z = $('#image-cropper');
z.cropit({
    exportZoom: 1,
    imageBackground: true,
    imageBackgroundBorderWidth: 15 // Width of background border
});

Try this: http://jsfiddle.net/grzveb09/

like image 152
Reza-S4 Avatar answered Nov 15 '22 08:11

Reza-S4