Skip to content

Commit fea7066

Browse files
committed
Fixed profile image
1 parent c15b80f commit fea7066

2 files changed

Lines changed: 40 additions & 39 deletions

File tree

src/func.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,30 @@ function wa_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_outpu
7575
function preprocessProfilePicture($path)
7676
{
7777
list($width, $height) = getimagesize($path);
78-
if ($width != $height) {
79-
throw new Exception("Profile picture needs to be square (image is $width x $height)");
80-
}
81-
if ($width > 640) {
82-
throw new Exception("Profile picture maximum size of 640 x 640 (image is $width x $height)");
78+
if ($width > $height) {
79+
$y = 0;
80+
$x = ($width - $height) / 2;
81+
$smallestSide = $height;
82+
} else {
83+
$x = 0;
84+
$y = ($height - $width) / 2;
85+
$smallestSide = $width;
8386
}
84-
$img = imagecreatefromjpeg($path);
85-
unlink($path);
86-
imagejpeg($img, $path, 50);
87+
88+
$size = 639;
89+
$image = imagecreatetruecolor($size, $size);
90+
$img = imagecreatefromstring(file_get_contents($path));
91+
92+
imagecopyresampled($image, $img, 0, 0, $x, $y, $size, $size, $smallestSide, $smallestSide);
93+
ob_start();
94+
imagejpeg($image);
95+
$i = ob_get_contents();
96+
ob_end_clean();
97+
98+
imagedestroy($image);
8799
imagedestroy($img);
100+
101+
return $i;
88102
}
89103

90104
function createIcon($file)

src/whatsprot.class.php

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class WhatsProt
4646
const WHATSAPP_SERVER = 's.whatsapp.net'; // The hostname used to login/send messages.
4747
const WHATSAPP_UPLOAD_HOST = 'https://mms.whatsapp.net/client/iphone/upload.php'; // The upload host.
4848
const WHATSAPP_DEVICE = 'Android'; // The device name.
49-
const WHATSAPP_VER = '2.11.471'; // The WhatsApp version.
50-
const WHATSAPP_USER_AGENT = 'WhatsApp/2.11.471 Android/4.3 Device/GalaxyS3'; // User agent used in request/registration code.
49+
const WHATSAPP_VER = '2.11.473'; // The WhatsApp version.
50+
const WHATSAPP_USER_AGENT = 'WhatsApp/2.11.473 Android/4.3 Device/GalaxyS3'; // User agent used in request/registration code.
5151
const WHATSAPP_VER_CHECKER = 'https://coderus.openrepos.net/whitesoft/whatsapp_version'; // Check WhatsApp version
5252

5353
/**
@@ -3775,35 +3775,22 @@ protected function sendRequestFileUpload($b64hash, $type, $size, $filepath, $to,
37753775
*/
37763776
protected function sendSetPicture($jid, $filepath)
37773777
{
3778-
if(stripos($filepath, 'http')!== false && !preg_match('/\s/',$filepath)){
3779-
$extension = end(explode(".", $filepath));
3780-
$newImageName = rand(0, 100000);
3781-
$imagePath = static::PICTURES_FOLDER."/".$newImageName.".jpg";
3782-
if($extension == 'jpg'){
3783-
copy($filepath, $imagePath);
3784-
$filepath = $imagePath;
3785-
}
3786-
}
3787-
preprocessProfilePicture($filepath);
3788-
$fp = @fopen($filepath, "r");
3789-
if ($fp) {
3790-
$data = fread($fp, filesize($filepath));
3791-
if ($data) {
3792-
//this is where the fun starts
3793-
$picture = new ProtocolNode("picture", array("type" => "image"), null, $data);
3794-
3795-
$hash = array();
3796-
$nodeID = $this->createMsgId("setphoto");
3797-
$hash["id"] = $nodeID;
3798-
$hash["to"] = $this->getJID($jid);
3799-
$hash["type"] = "set";
3800-
$hash["xmlns"] = "w:profile:picture";
3801-
$node = new ProtocolNode("iq", $hash, array($picture), null);
3802-
3803-
$this->sendNode($node);
3804-
$this->waitForServer($nodeID);
3805-
}
3806-
}
3778+
$data = preprocessProfilePicture($filepath);
3779+
$preview = createIconGD($filepath, 96, true);
3780+
3781+
$picture = new ProtocolNode("picture", array("type" => "image"), null, $data);
3782+
$preview = new ProtocolNode("picture", array("type" => "preview"), null, $preview);
3783+
3784+
$hash = array();
3785+
$nodeID = $this->createMsgId("setphoto");
3786+
$hash["id"] = $nodeID;
3787+
$hash["to"] = $this->getJID($jid);
3788+
$hash["type"] = "set";
3789+
$hash["xmlns"] = "w:profile:picture";
3790+
$node = new ProtocolNode("iq", $hash, array($picture, $preview), null);
3791+
3792+
$this->sendNode($node);
3793+
$this->waitForServer($nodeID);
38073794
}
38083795
/**
38093796
* Parse the message text for emojis

0 commit comments

Comments
 (0)