Skip to content

Commit

Permalink
Closes #5 by adding ability to specify view
Browse files Browse the repository at this point in the history
Added ability to specify view for facial avatar; front, left, right, or
back
  • Loading branch information
jamiebicknell committed Sep 8, 2014
1 parent 8d77e5e commit 415ca14
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]

RewriteRule ^skin/([^/]+)/([^/]+)$ skin.php?u=$1&s=$2
RewriteRule ^skin/([^/]+)$ skin.php?u=$1
RewriteRule ^avatar/([^/]+)/([^/]+)/(f|l|r|b|front|left|right|back)$ face.php?u=$1&s=$2&v=$3
RewriteRule ^avatar/([^/]+)/(f|l|r|b|front|left|right|back)$ face.php?u=$1&v=$2
RewriteRule ^avatar/([^/]+)/([^/]+)$ face.php?u=$1&s=$2
RewriteRule ^avatar/([^/]+)$ face.php?u=$1
RewriteRule ^skin/([^/]+)/([^/]+)$ skin.php?u=$1&s=$2
RewriteRule ^skin/([^/]+)$ skin.php?u=$1
</ifModule>
74 changes: 63 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,37 @@ If username is not found, then it uses the default skin: [http://www.minecraft.n
<img src='http://jamiebicknell.github.io/Minecraft-Avatar/1379352360571.png' alt='Steve Avatar' />

```html
<img src='face.php?u={username}&s={size}' />
<img src='face.php?u={username}&s={size}&v={view}' />
```

Where `{size}` can be between 8 and 250 pixels

### Query Parameters

<table>
<tr>
<th>Key</th>
<th>Example Value</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>u</td>
<td>jamiebicknell</td>
<td><a href='http://www.minecraft.net/skin/char.png'>steve</a></td>
<td>Username of Minecraft player</td>
</tr>
<tr>
<td>s</td>
<td>8 - 250</td>
<td>48</td>
<td>Desired avatar width and height</td>
</tr>
<tr>
<td>v</td>
<td>f, l, r, b<br />front, left, right, back</td>
<td>front</td>
<td>View of facial avatar (optional)</td>
</tr>
</table>

## Skin Preview

Expand All @@ -21,32 +48,57 @@ Where `{size}` can be between 8 and 250 pixels
```html
<img src='skin.php?u={username}&s={size}' />
```

Where `{size}` can be between 40 and 800 pixels

### Query Parameters

<table>
<tr>
<th>Key</th>
<th>Example Value</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>u</td>
<td>jamiebicknell</td>
<td><a href='http://www.minecraft.net/skin/char.png'>steve</a></td>
<td>Username of Minecraft player</td>
</tr>
<tr>
<td>s</td>
<td>40 - 800</td>
<td>250</td>
<td>Desired skin preview width</td>
</tr>
</table>

## .Htaccess

If you have `mod_rewrite` enabled you can view the avatar via cleaner URLs.

For an avatar without a size:
### Facial Avatar

```html
<img src='http://domain.com/avatar/{username}' />
```

For an avatar with a size:

```html
<img src='http://domain.com/avatar/{username}/{size}' />
```

For a skin without a size:
```html
<img src='http://domain.com/avatar/{username}/{view}' />
```

```html
<img src='http://domain.com/avatar/{username}/{size}/{view}' />
```

### Skin Preview

```html
<img src='http://domain.com/skin/{username}' />
```

For a skin with a size:

```html
<img src='http://domain.com/skin/{username}/{size}' />
Expand Down
12 changes: 9 additions & 3 deletions face.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

$size = isset($_GET['s']) ? max(8, min(250, $_GET['s'])) : 48;
$user = isset($_GET['u']) ? $_GET['u'] : 'char';
$view = isset($_GET['v']) ? substr($_GET['v'], 0, 1) : 'f';
$view = in_array($view, array('f', 'l', 'r', 'b')) ? $view : 'f';

function get_skin($user = 'char')
{
Expand Down Expand Up @@ -55,9 +57,13 @@ function get_skin($user = 'char')

$im = imagecreatefromstring($skin);
$av = imagecreatetruecolor($size, $size);
imagecopyresized($av, $im, 0, 0, 8, 8, $size, $size, 8, 8); // Face
imagecolortransparent($im, imagecolorat($im, 63, 0)); // Black Hat Issue
imagecopyresized($av, $im, 0, 0, 40, 8, $size, $size, 8, 8); // Accessories

$x = array('f' => 8, 'l' => 16, 'r' => 0, 'b' => 24);

imagecopyresized($av, $im, 0, 0, $x[$view], 8, $size, $size, 8, 8); // Face
imagecolortransparent($im, imagecolorat($im, 63, 0)); // Black Hat Issue
imagecopyresized($av, $im, 0, 0, $x[$view] + 32, 8, $size, $size, 8, 8); // Accessories

header('Content-type: image/png');
imagepng($av);
imagedestroy($im);
Expand Down

3 comments on commit 415ca14

@Coolechriz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanx but i mean this for (https://github.com/jamiebicknell/Minecraft-Avatar/blob/master/skin.php) because it is now every rotate at one.

@jamiebicknell
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seemed to have misunderstood your original idea, sorry. I do think this is a good addition though and I'm glad I built in this feature, so thanks for that anyway.

Regarding the skin.php, it will cause some issues because you specify the width (and the height is automatically calculated). So if you have two images; front and left side, each with a size (width) of 200, then the left size will be much taller.

Another issue is that the nature of the preview is to preview all sides, it was built for this purpose alone, and that's why it has padding horizontally and vertically so that it fits nicely in a fixed with area.

What you are suggesting will require a new feature that doesn't have the padding, and only shows one whole view, and that the size sets the height so that the height remains constant for different views. I feel this overcomplicates what I'm going for with this script, but will give it some thought anyway.

@Coolechriz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this really would work it would be very nice. For me it still in no hurry since I no pictures use now, but I do want to do this.

Thank you very much if you made ​​this !!

Sorry for my bad English i'm Dutch.

Please sign in to comment.