Crop image with react-native - crop

Hello World,
I trying to crop an image like explain on the React-native Doc
<Image source={{uri: this.props.image, crop: {left: 50, top: 50, width: 100, height: 100}}} style={{height: 100, width: 100}}/>
But it's doesn't work the image is not cropped.
Any idea?

From the docs:
On the infrastructure side, the reason is that it allows us to attach metadata to this object. For example if you are using require('./my-icon.png'), then we add information about its actual location and size (don't rely on this fact, it might change in the future!). This is also future proofing, for example we may want to support sprites at some point, instead of outputting {uri: ...}, we can output {uri: ..., crop: {left: 10, top: 50, width: 20, height: 40}} and transparently support spriting on all the existing call sites.
React Native Image is not currently supporting image cropping, at least not the way you pointed, however you still have other options that will do the same job.
ImageEditor:
React Native Component, again from the docs:
Crop the image specified by the URI param. If URI points to a remote
image, it will be downloaded automatically. If the image cannot be
loaded/downloaded, the failure callback will be called.
Cropping doesn't require linking.
Image Crop Picker another package that offers cropping, but in a different way: Picking. Requires linking, but thankfully it also supports RN versions > 0.40.
I haven't used any of them, but if I were you, I would first try Image Editor, since you don't need any additional installation except importing.

you can use package for cropping the image. first package for uploading image and second for cropping the image.
react-native-image-picker
react-native-image-crop-picker
for uploading image you can use first package function like this
const pickImage = () => {
launchImageLibrary({quality: 0.5}, response => {
if (!response.didCancel) {
setUri(response.assets[0]);
setCropImg('');
}
});
};
for cropping the image you can use second package function like this
const Crop_img = () => {
ImagePicker.openCropper({
path: uri.uri,
width: dimensions.width - 30,
height: dimensions.height / 3.5,
maxFiles: 1,
showCropFrame: false,
}).then(image => {
console.log(image.path);
setCropImg(image.path);
});
};

Related

How to take a full resolution picture with camera in nativescript?

I'd like to take a full resolution picture with nativescript camera module ... but i can't !
I know how to do that with cordova but not in nativescript :-( and all examples are with small res like 300x300.
const options = {
width: 300,
height: 300,
keepAspectRatio: false,
saveToGallery: true
};
I'm looking for something like "0x0" or no width and height options but if i try to put 4096x3072 (my camera resolution) the result is "out of memory".
Thanks
Try to use nativescript media file picker https://www.npmjs.com/package/nativescript-mediafilepicker Or nativescript camera plus https://market.nativescript.org/plugins/#nstudio%2Fnativescript-camera-plus for full screen camera.

React Native Image resizeMode='contain' not working

I can't get resizeMode='contain' to work for images loaded remotely, wondering if there's something I've done wrong.
Render Method:
return (
<View style={styles.internal_button_avatar_container}>
<Image
style={styles.internal_button_avatar_image}
source={{ uri: this.state.imageURL }}
loadingIndicatorSource={require('../assets/icons/PageLink-Loading.png')}
resizeMode={'contain'}
/>
</View>
);
Styles (relevant section):
internal_button_avatar_container: {
marginRight: 10,
width: 40,
height: 40,
},
internal_button_avatar_image: {
width: 40,
height: 40,
},
I've tried resizeMode='contain' and resizeMode='center' but the image always is cropped around the outside of it's frame. Screenshot showing cropped icon.. I've also tried with undefined height and width on the image.
The cropping only appears to happen if the source image is not the same aspect ratio as the frame, a square source will result in perfectly scaled image.
I tried to reproduce your situation, but I haven't problems with that in this snack:
https://snack.expo.io/#gersonmontenegro/resizemode
The original size of the image is bigger than the container, even it has a different aspect radio, and it has loaded according to the internal_button_avatar_image.
Is ok for you?
Turns out I was getting the image from an endpoint in an API that auto-cropped the original image - should've checked the source image before everything else!

Circular image edges are jagged in Alloy appcelerator

I am trying to make an circular image view in Alloy appcelerator formerly Titanium like this
XML
<ImageView id="profile_photo" />
TSS
"#profile_photo_view_holder":{
width: 80,
height: 80,
borderRadius: 40,
borderWidth:2,
borderColor:"black"
}
The image view is rendering properly but jaggy in its edges looks like an anti aliasing problem.
I use image factory module to scale down also but no luck.
resizedImage = ImageFactory.imageAsResized(blob, {
width : 80,
height : 80,
quality : 0.9
});
$.profile_photo.image = resizedImage;
on Android you will need to make use of a module to achieve it.
This module is quite new and looks great:
https://github.com/m1ga/com.miga.roundview
I'm using this one in my project:
https://github.com/snowciety/sc.roundedavatar
Hope it helps

How to use FineUploader Core with JCrop to Crop and Upload an image

I am aware of this question-Fineuploader - add jqCrop.
However my challenge is that i do not want to use a generic file input that add jCrop as a listener.I am a newbie with FineUploader.Can some expert confirm if this is the most appropriate steps to follow.
form: {
element:document.getElementById('fileinput_inline')
}
$('#image_input img').Jcrop({
bgColor: 'black',
bgOpacity: .6,
setSelect: [0, 0, 100, 100],
aspectRatio: 1,
onSelect: imgSelect,
onChange: imgSelect
});
Use FineUploader Core form.element option to bind my file input to FineUpload
Use FineUploader validation options to validate size,filetype, etc
At the onSubmitted event ,retrieve the file id and use the drawThumbnail method to insert a preview in an image html element (<img id='image_input'/>)
Introduce jCrop.
Submit the cropped Blob to Fine Uploade
uploader.addBlobs({blob: croppedImageAsBlob, name: "my cropped image.png"});
Fire the upload to server
Your outlined steps look to be appropriate, but the selector tied to jcrop looks incorrect.
For this element: <img id='image_input'/>, your selector string should be '#image_input'.

How to draw a line on image using appcelerator titanium mobile

I'm want to make an application for Galaxy Tab, that allows me to draw pictures... Something similar to MS Paint (don't ask my why :)) so the first steps are:
win = Ti.UI.createWindow({
backgroundColor: 'black',
exitOnClose: true
});
image = Ti.UI.createImageView({
width: 200,
height: 200
});
image.addEventListener('touchmove', function(e){
//And here I need somehow to draw a pixel on image at e.x, e.y coordinates
// How can i do it?
});
So, how should i draw a pixel?
sorry I have not read you full Question.
try This, this is a Titanium Appcelerator Module and this is absoultely free
It have also a easy example. You can use easy.
Again Really Sorry..

Resources