Skip to content

Commit aa2ef37

Browse files
committed
quick, ghetto script to rescale profile pictures
Summary: we had a hole in scaling pics from oauth from a bit. that was patched in D2848. this cleans up the old data. Test Plan: ran it in production. issue as described on task is resolved. also spot checked some profiles and they look good. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1634 Differential Revision: https://secure.phabricator.com/D3268
1 parent 66cee12 commit aa2ef37

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* Copyright 2012 Facebook, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
$root = dirname(dirname(dirname(__FILE__)));
21+
require_once $root.'/scripts/__init_script__.php';
22+
23+
echo "Examining users.\n";
24+
foreach (new LiskMigrationIterator(new PhabricatorUser()) as $user) {
25+
$file = id(new PhabricatorFile())
26+
->loadOneWhere('phid = %s', $user->getProfileImagePHID());
27+
28+
if (!$file) {
29+
echo 'No pic for user ', $user->getUserName(), "\n";
30+
continue;
31+
}
32+
33+
$data = $file->loadFileData();
34+
$img = imagecreatefromstring($data);
35+
$sx = imagesx($img);
36+
$sy = imagesy($img);
37+
38+
if ($sx != 50 || $sy != 50) {
39+
echo 'Found one! User ', $user->getUserName(), "\n";
40+
$xformer = new PhabricatorImageTransformer();
41+
42+
// Resize OAuth image to a reasonable size
43+
$small_xformed = $xformer->executeProfileTransform(
44+
$file,
45+
$width = 50,
46+
$min_height = 50,
47+
$max_height = 50);
48+
49+
$user->setProfileImagePHID($small_xformed->getPHID());
50+
$user->save();
51+
break;
52+
} else {
53+
echo '.';
54+
}
55+
}
56+
echo "\n";
57+
echo "Done.\n";

0 commit comments

Comments
 (0)