I've created a support forum where people frequently attach images taken by Lightshot Screenshot. They generally add the uploaded URL (like https://prnt.sc/ujaclu) to the forum. Basically all the images attached by uploading are previewed to the forum. But from the Lightshot URL, I cannot get any image.
Could anyone help me to parse the Lightshot URL (https://prnt.sc/ujaclu) as I can use it to an src URL of <img /> tag using JavaScript?
Note: I didn't get any hint on how to do it. I am completely stuck on it.
I wrote a solution for the Lightshot image extraction using Javascrit : LightShot Image Extractor
Here is the code:
const cheerio = require('cheerio')
const axios = require('axios')
/**
* Extracts the jpg url from a LightShot page
* lightshot_image('http://prntscr.com/dki21q')
* http://image.prntscr.com/image/1aaf571d0adf4aa098eb565bbb196af6.png
*/
async function lightshotImageExtractor(url) {
try {
const { data } = await axios.get(url)
const imgUrl = parseHTML(data)
return imgUrl
} catch (err) {
console.log(err)
return null
}
}
function parseHTML(html) {
const $ = cheerio.load(html)
const rows = $('.screenshot-image')
if (rows.length > 0 && rows[0].attribs && rows[0].attribs.src) {
return rows[0].attribs.src
}
return null
}
lightshotImageExtractor('http://prntscr.com/dki21q').then((url) =>
console.log(url),
)
The link you are trying to use to show the image is not images url. It is url of a page. That's why it is not showing any image.
This is the actual url of the image https://image.prntscr.com/image/EdCTchd1TLit-Gg1Mtt-pg.png
Contact with them and ask them if they can help you with their link decryption.
Related
When I hit upload the picture gets uploaded to firebase Storage, but i cant seem to get the image url, I can go to the Storage tab on firebase click on the image and click on its ling , copy the link in and then past it into the DATABASE were i need it for display and it will work, But i dont see an image URL or A download URL when i consolo.log the snapshot of the const TASK!
I fear that the method:
const task = uploadBytesResumable(storeref, ImSRC, metdata)
that iam using to upload the image does not produce an image url! Could This be So?
!!!HERE IS ALL THE CODE FOR THE UPLOAD BUTTON !!
Upload.addEventListener('click', (e) =>{
let ImSRC = files[0];
if(ImSRC == null ){
alert('no picture selected');
}else{
const metdata = {
contentType: ImSRC.type
}
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
})
}
console.log(ProPicUrl);
});
}
});
Getting the download URL from Firebase Storage is (like uploading the data itself) an asynchronous operation. Just like any code that needs to run after the upload has completed needs to be inside the then() block for that task, the code that needs to run after the download URL has been determined has to be inside the then() block for that task too.
So:
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
console.log(ProPicUrl);
})
}
});
I am facing a problem related to uploading images in firebase storage. I am able to upload user images in firebase storage but it is only showing the newest image. it is not showing previous images. I think it is because of the path that I have created and the timestamp in this line of code:
const path = 'photos/${Date.now()}.jpg';
I am using expo and React. Here is the code for uploading images:
uploadPhotoAsync = async uri => {
const path = 'photos/${Date.now()}.jpg';
return new Promise (async(res, rej) => {
const response = await fetch(uri)
const file = await response.blob()
let upload = firebase.storage().ref(path).put(file)
upload.on("state_changed", snapshot=>{
}, err => {
rej(err)
}, async ()=>{
const url = await upload.snapshot.ref.getDownloadURL()
res(url)
})
})
}
Thank you.
There are several errors in your code:
Template literals should be delimited with backticks (`), while you delimit yours with standard single quotes ('): const path = 'photos/$(Date.now()}.jpg';.
Result: The value of path is always the same.
In addition, after the $ you use a parenthesis instead of a curly bracket.
Doing as follows shall do the trick:
const path = `photos/${Date.now()}.jpg`
I want to share an image file directly to my whatsApp or add it to my whatsApp status i.e I don't want to see any other sharing option when I click on button to share any image.
Currently I am using the following code to share
import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';
const customShare = async (image) => {
const base64result = image.split(',')[1];
try {
let filename = 'share.png'; // or some other way to generate filename
let filepath = `${FileSystem.documentDirectory}/${filename}`;
await FileSystem.writeAsStringAsync(filepath, base64result, { encoding: 'base64' });
await Sharing.shareAsync(filepath, { mimeType: 'image/gif' })
} catch (e) {
alert(e.message);
}
};
But here it is showing all sharing option to choose, is there any way to skip this step and directly open my WhatsApp
I have a simple function that tries to base64-encode an image and upload it to IPFS:
async function toIPFS() {
const node = await IPFS.create()
const data = fs.readFileSync('./src/assets/logo.png', 'base64').toString('base64')
const results = await node.add(data)
console.log(results.cid.string)
}
However, when I actually check the hash it displays as a long string:
iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHB...etc
How do I upload an image such that it actually displays as an image? What am I missing?
I've never worked with images so pardon if this is a noob question:)
What you're seeing returned is the file encoded as base64, if you want to store the image itself for later retrieval, this is how you'd do it:
async function toIPFS() {
const node = await IPFS.create()
const data = fs.readFileSync('./src/assets/logo.png')
const results = await node.add(data)
console.log(results.cid.string)
}
I try to use https://github.com/bradmartin/nativescript-drawingpad for saving a signature to my backend. But I am simply not capable to find a solution to get some "useful" data from getDrawing(), which returns a native image Object, for example UIImage on iOS.
I would love to "convert" the image data to some base64 (png, or whatever) string and send it to my server.
I tried someting like:
var ImageModule = require("ui/image");
var ImageSourceModule = require("image-source");
elements.drawingpad.getDrawing().then(function(a){
var image = ImageSourceModule.fromNativeSource( a );
api.post("sign", image.toBase64String());
});
I also tried to post simply a like seen in the demo stuff.
I would really love to see a demo of how to get my hands on the "image data" itself.
thanks!
Thanks to #bradmartin I found the solution:
var image = ImageSourceModule.fromNativeSource(a);
var base64 = image.toBase64String('png');
Actually after lots of digging with tons of error, I finally figured it out.
First you have to require the nativescript-imagepicker source module and also the nativescript image source.
var imagepicker = require("nativescript-imagepicker");
var ImageSourceModule = require("tns-core-modules/image-source");
a case where you want to update a user profile and also send a base64 string to your backend for processing
function changeProfileImage(args) {
var page = args.object;
var profile = page.getViewById("profile-avatar");
var context = imagepicker.create({ mode: "single" });
context.authorize().then(function() {
return context.present();
}).then(function(selection) {
profile.background = `url(${selection[0]._android})`;
profile.backgroundRepeat = `no-repeat`;
profile.backgroundSize = `cover`;
ImageSourceModule.fromAsset(selection[0]).then(image => {
var base64 = image.toBase64String('png');
// console.log(base64);
uploadMediaFile(base64);
});
}).catch(function (e) {
// process error
console.log(e);
});
}