fengyuanchen cropper how to set up dynamic fixed crop box

fengyuanchen cropper how to set up dynamic fixed crop box



I'm using a crop tool from fengyuanchen, which has awesome features. I'm trying to make a fixed crop-box with dynamic sizes.



But I'm currently stuck just on how to figger out how to make it a certain size.



I've tried the following:


$(function()

$('.img-container > img').cropper(
aspectRatio: 16 / 9,
autoCropArea: 0.65,
strict: false,
guides: false,
highlight: false,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
setCropBoxData('1600', '1200')
);

);



But setCropBoxData doesn't work for me. What am I doing wrong?


setCropBoxData



UPDATE



This should be the correct syntax to set up a fixed width for that actual cropbox, but I still don't get any results:


$(function()
var $toCrop = $('.img-container > img');

$toCrop.cropper(
aspectRatio: 16 / 9,
autoCropArea: true,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
built: function ()
$toCrop.cropper("setCropBoxData", width: "100", height: "50" );

);
);





Check your browser console: the code you posted is syntactically incorrect, and you'll see an error.
– Pointy
Jul 14 '15 at 13:12




2 Answers
2



I've finaly found the solution. My mistake was that I was passing string instead of number as parameters to setCropBoxData function.


string


number


setCropBoxData



Here is the correct syntax:


$(function()
var $toCrop = $('.img-container > img');

$toCrop.cropper(
aspectRatio: 16 / 9,
autoCropArea: 0,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false,
built: function ()
// Width and Height params are number types instead of string
$toCrop.cropper("setCropBoxData", width: 1600, height: 800 );

);
);



Go back and re-read the "Methods" section of the documentation. That shows you how to invoke functions like that. Also note that "setCropBoxData" expects an object with "top", "left", "width", and "height" properties:


$(function()
var $img = $('.img-container > img');
$img.cropper(
aspectRatio: 16 / 9,
autoCropArea: 0.65,
strict: false,
guides: false,
highlight: false,
dragCrop: false,
cropBoxMovable: false,
cropBoxResizable: false
);
$img.cropper("setCropBoxData", width: "1600", height: "1200" );
);





I don't have any errors anymore now, but still there is no reaction from the cropbox. It is still the same for me.
– Jeroen Bellemans
Jul 14 '15 at 13:19





It looks like "setCropBoxData" expects an object, not just a pair of numbers. I'll update the answer.
– Pointy
Jul 14 '15 at 13:28





Thanks, but still no positive changes, I'll try to make a jsfiddle
– Jeroen Bellemans
Jul 14 '15 at 13:34






@JeroenBellemans it may be hard to make a fiddle unless you have a CORS-friendly image host
– Pointy
Jul 14 '15 at 14:02





Thanks for the help! I've found the solution
– Jeroen Bellemans
Jul 15 '15 at 7:37




Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế