We are about to switch to a new forum software. Until then we have removed the registration on this forum.
in case someone ever needs this:
This code is able to separate each post of **a Whatsapp Web screenshot **and save it as individual files. If you use the firefox plugin fireshot you can export a whole chat as a single image. Process the image with this code and you get a image for each post. Fireshot automatically exports only the message field, which is required for the script below. A WhatsApp Web Screenshot looks like this:
Note: you may have to increase memory to 1000MB or more in settings for long chats.
//WhatsApp Web Screenshot Slicer 2016
//Use Firefox Addin fireshot to export the chat image.
PImage img;
int colc;
int cold;
int cole;
int p1;
int p2;
int p=10;
int flag=1;
int found=0;
int xlen=1185; // width of screenshot
void setup() {
size(xlen, 24999); // dimensions of chat image, check these!
img = loadImage("Anna.png"); //chat image, must be in data folder of sketch
image(img, 0, 0);
slicen();
}
void slicen() {
int x1 = -1712683;
int x2 = -3686215;
int x3 = -3160128;
int x4 = -2699577;
for (int i = 0; i < img.height; i++) {
color c= get(200, i); colc = int(c); // x-values depend on screen resolution
color d= get(600, i); cold = int(d);
color e= get(800, i); cole = int(e);
if ((colc==x1||colc==x2||colc==x3||colc==x4)&&(cold==x1||cold==x2||cold==x3||cold==x4)&&(cole==x1||cole==x2||cole==x3||cole==x4)){
found=1; // normal case
}
if ((colc==x1||colc==x2||colc==x3||colc==x4)&&(cold!=x1&&cold!=x2&&cold!=x3&&cold!=x4)&&(cole==x1||cole==x2||cole==x3||cole==x4)){
found=1; //special case where date bubble is in the way of two posts
}
if (found == 1) {
found=0;
if (flag==2){
p2 = i;
if (p2-p1==1){flag=1;}
if (p2-p1 > 1) {
PImage img2 = createImage(xlen, p2-p1, RGB);
img2.loadPixels();
for (int ii = 0; ii < img2.pixels.length; ii++) {
img2.pixels[ii] = img.pixels[p1*xlen+ii];
}
img2.updatePixels();
p=p+1;
img2.save("/images/"+str(p)+".png"); // create folder images in sketch!
flag=1;
}
}
if (flag==1){ p1 = i; flag=2; }
}
}
}
Comments
Format your code. Edit post, select your code and hit ctrl+o.
Kf
thx, didn't find the possibility.
@gogolo -- could you say something about what this does?
Are the screenshots that it slices originally taken from a browser, or taken from an OS-specific desktop app, or a mobile device? What parts gets sliced off and saved?
It would also help if you could point to a single example image of the kind of WhatsApp screenshot that this program would work on -- either online, or upload an example here.
ok, hope it helps.
Thanks @gogolo!
Very interesting use of color detection to crop the individual messages.
thx! updated the code and commented. processing is great and fast!