check_feature('feature_userPreferences'); $access->check_user($user); /** @var UserPrefsLib $userprefslib */ $userprefslib = TikiLib::lib('userprefs'); if (empty($userwatch)) { $userwatch = $user; } $data = file_get_contents($url); list($iwidth, $iheight, $itype, $iattr) = getimagesize($url); $itype = image_type_to_mime_type($itype); // Get proper file size of image $imgdata = get_headers($url, true); if (isset($imgdata['Content-Length'])) { # Return file size $size = (int)$imgdata['Content-Length']; } else { $size = strlen($data); } // Store full-size file gallery image if that is required if ($prefs["user_store_file_gallery_picture"] == 'y') { $fgImageId = $userprefslib->set_file_gallery_image($userwatch, $name, $size, $itype, $data); $file = \Tiki\FileGallery\File::id($fgImageId); $data = $file->getContents(); } // Store small avatar if ($prefs['user_small_avatar_size']) { $avsize = $prefs['user_small_avatar_size']; } else { $avsize = "45"; //default } if (($iwidth == $avsize and $iheight <= $avsize) || ($iwidth <= $avsize and $iheight == $avsize)) { $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $itype, $data); } else { if (function_exists('imagecreatefromstring') && (! strstr($itype, 'gif'))) { $img = imagecreatefromstring($data); $size_x = imagesx($img); $size_y = imagesy($img); /* if the square crop is set, crop the image before resizing */ if ($prefs['user_small_avatar_square_crop']) { $crop_size = min($size_x, $size_y); $offset_x = ($size_x - $crop_size) / 2; $offset_y = ($size_y - $crop_size) / 2; $crop_array = ['x' => $offset_x , 'y' => $offset_y, 'width' => $crop_size, 'height' => $crop_size]; $img = imagecrop($img, $crop_array); $size_x = $size_y = $crop_size; } if ($size_x > $size_y) { $tscale = ((int)$size_x / $avsize); } else { $tscale = ((int)$size_y / $avsize); } $tw = ((int)($size_x / $tscale)); $ty = ((int)($size_y / $tscale)); if ($tw > $size_x) { $tw = $size_x; } if ($ty > $size_y) { $ty = $size_y; } if (chkgd2()) { $t = imagecreatetruecolor($tw, $ty); // trick to have a transparent background for png instead of black imagesavealpha($t, true); $trans_colour = imagecolorallocatealpha($t, 0, 0, 0, 127); imagefill($t, 0, 0, $trans_colour); imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } else { // TODO ImageGalleryRemoval23.x - replace imagick if no GD } // CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY $tmpfname = tempnam($prefs['tmpDir'], "TMPIMG"); imagepng($t, $tmpfname); // Now read the information $fp = fopen($tmpfname, "rb"); $t_data = fread($fp, filesize($tmpfname)); fclose($fp); unlink($tmpfname); $t_type = 'image/png'; $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $t_type, $t_data); } else { $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $itype, $data); } } TikiLib::events()->trigger( 'tiki.user.avatar', [ 'type' => 'user', 'object' => $userwatch, 'user' => $userwatch, ] ); } }