+
+ static function newSize(Profile $target, $size) {
+ $size = floor($size);
+ if ($size <1 || $size > 999) {
+ // TRANS: An error message when avatar size is unreasonable
+ throw new Exception(_m('Unreasonable avatar size'));
+ }
+
+ $original = Avatar::getOriginal($target);
+
+ $imagefile = new ImageFile($target->id, Avatar::path($original->filename));
+ $filename = $imagefile->resize($size);
+
+ $scaled = clone($original);
+ $scaled->original = false;
+ $scaled->width = $size;
+ $scaled->height = $size;
+ $scaled->url = Avatar::url($filename);
+ $scaled->created = DB_DataObject_Cast::dateTime();
+
+ if (!$scaled->insert()) {
+ // TRANS: An error message when unable to insert avatar data into the db
+ throw new Exception(_m('Could not insert new avatar data to database'));
+ }
+
+ // Return the new avatar object
+ return $scaled;
+ }