Coder Social home page Coder Social logo

Comments (19)

DevotionGeo avatar DevotionGeo commented on June 28, 2024 1

@scottcheng when we set minZoom: to 'fit', the image while zoomed out moves freely. The user is not always very genius, so sometimes they move image to one side of the canvas (example-1), how can we force it centered while its smaller than the canvas (example-2)?
Following are the example images.


example-1 :

image to one side


example-2 :

image centered


from cropit.

nyn0x avatar nyn0x commented on June 28, 2024 1

@DevotionGeo I fixed with css :
.cropit-preview-image{ float: left; }

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

Sorry I don't quite understand what you mean here. So we have a square cropping box and the user uploads a non-square image, I'm not quite sure what you mean by "fitting the image on the container"? Perhaps some screenshots would help a lot.

from cropit.

tomByrer avatar tomByrer commented on June 28, 2024

I'm thinking @javiermarinros wants the image to automatically fill one axis (height or width) with the other axis to overflow/be-cropped?

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

@tomByrer Isn't that how it currently works? See the first demo on the website.

from cropit.

javiermarinros avatar javiermarinros commented on June 28, 2024

Here it's an example: I have a big horizontal photo that I want to use as an square icon. With cropit, I can't fit it into the container.

This is what I can do now:

cropit

And this what I want to achieve:

ideatic gestionatic

I hope I've explained myself

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

@javiermarinros Thanks for clarifying. So you want to zoom the image so it's smaller than the container. The tricky part here is a) what's the smallest zoom you want the image to be able to go? Should it be small enough to fit the width or the height? and b) what do we do with the part outside the image? Fill with #fff?

In fact there are two undocumented options fitWidth and fitHeight. For example, if you pass in fitWidth: true, you will be able to zoom out until the image width fits the container width, even if the height goes smaller than the container:

image

But then you won't be able to drag it up and down, and the exported image will not include the part outside of the image.

I guess technically what you are suggesting is not really "cropping"; it feels more like "expanding"... I agree that a cropper could support such functionality, but would have to add multiple option parameters, e.g. minimum zoom and background fill color. What do you think?

from cropit.

javiermarinros avatar javiermarinros commented on June 28, 2024

I think that, as you said, the smallest zoom should be that able to fit the width or height of the image. And the background can be transparent for PNG images, and the color given in the option fillBg introduced in PR#19 for JPEGs.

You've most of the work done with fitWidth and fitHeight! It works exactly as I expected, but it would be better if the user can drag the image up and down.

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

@javiermarinros @phunksta I've added a minZoom option in 34f79e3 which works as follows:

minZoom decides the minimal zoom level of the image. If set to 'fill', the image has to fill the preview area, i.e. both width and height must not go smaller than the preview area. If set to 'fit', the image can shrink further to fit the preview area, i.e. at least one of its edges must not go smaller than the preview area.

The default value is 'fill', consistent with previous default setting. Feel free to try it out (it's in the current master) and let me know how it works for you. Thanks!

from cropit.

javiermarinros avatar javiermarinros commented on June 28, 2024

It works like a charm! For other users that wanted to replicate the same behaviour, you must set minZoom to fit and freeMove to true and you'll get a image cropper that allows the user to upload an image of any shape and adjust and center it to the size you need for your app.

Thank you!

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

@javiermarinros Thanks for testing! Did you have to set freeMove to true to move the image around after zooming out? You should be able to achieve what you described above in the screenshot by only setting minZoom to fit. It doesn't allow you to drag the image off the preview area, but you should be able to drag it up and down, if the image is wider than the preview area.

from cropit.

javiermarinros avatar javiermarinros commented on June 28, 2024

That's true! I didn't tried without freeMove, but it's better if the image cannot go off the preview area. Thank you!

from cropit.

PhilBlackRose avatar PhilBlackRose commented on June 28, 2024

Hey @scottcheng,
Sorry for the delay, I'm back on the project using cropit today.
After some initial 'duh' moments (I'm quite noob with github) I found the new source in the master and tried it out.
Brilliant! what more do I need to say? It works very nicely indeed thank you!

What's more you can now brag that yours is pretty much the only crop plugin that allows you to do this gracefully!

The only possible improvement I could think of is having buttons on the cropit form that allow this mode to be toggled. Is that just a case of changing the options object, or would the form need re-initialising?

Thanks again!

from cropit.

scottcheng avatar scottcheng commented on June 28, 2024

@phunksta Thanks for trying it out!

Regarding toggling the mode, I don't think changing the options object is the best approach. Neither is re-initializing. Ideally there should be an API for it, e.g. $el.cropit('minZoom', 'fit'). Do you have a real world use case for this?

from cropit.

PhilBlackRose avatar PhilBlackRose commented on June 28, 2024

No I think for our purposes what you've added is perfect. I just wasn't clear on how the options work, and you've answered that.
Thanks again! 

-------- Original message --------
From: Scott Cheng [email protected]
Date: 17/02/2015 5:59 PM (GMT+00:00)
To: scottcheng/cropit [email protected]
Cc: phunksta [email protected]
Subject: Re: [cropit] Adjust image to container (#20)

@phunksta Thanks for trying it out!

Regarding toggling the mode, I don't think changing the options object is the best approach. Neither is re-initializing. Ideally there should be an API for it, e.g. $el.cropit('minZoom', 'fit'). Do you have a real world use case for this?


Reply to this email directly or view it on GitHub.

from cropit.

Mattrad1 avatar Mattrad1 commented on June 28, 2024

If user crop an image 1 time and then want to crop the the croped image again.it does not show the image.How I can fix it?

from cropit.

CyrPen avatar CyrPen commented on June 28, 2024

.cropit-preview-image{ float: left; }

Exactly what i was looking for ! Thanks

from cropit.

kacpermaciejevvski avatar kacpermaciejevvski commented on June 28, 2024

Is there any way to 'cut' those 'transparent' sides of generated image, if the container is bigger than the image?

from cropit.

shadaba1974 avatar shadaba1974 commented on June 28, 2024

how to add flip/flop button along rotation button? any idea, please let me know?

from cropit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.