@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUIImageMaskExample extends PhabricatorUIExample {
4
5 public function getName() {
6 return pht('Image Masks');
7 }
8
9 public function getDescription() {
10 return pht('Display images with crops.');
11 }
12
13 public function renderExample() {
14 $image = celerity_get_resource_uri('/rsrc/image/examples/hero.png');
15 $display_height = 100;
16 $display_width = 200;
17
18 $mask1 = id(new PHUIImageMaskView())
19 ->addClass('ml')
20 ->setImage($image)
21 ->setDisplayHeight($display_height)
22 ->setDisplayWidth($display_width)
23 ->centerViewOnPoint(265, 185, 30, 140);
24
25 $mask2 = id(new PHUIImageMaskView())
26 ->addClass('ml')
27 ->setImage($image)
28 ->setDisplayHeight($display_height)
29 ->setDisplayWidth($display_width)
30 ->centerViewOnPoint(18, 18, 40, 80);
31
32 $mask3 = id(new PHUIImageMaskView())
33 ->addClass('ml')
34 ->setImage($image)
35 ->setDisplayHeight($display_height)
36 ->setDisplayWidth($display_width)
37 ->centerViewOnPoint(265, 185, 30, 140)
38 ->withMask(true);
39
40 $mask4 = id(new PHUIImageMaskView())
41 ->addClass('ml')
42 ->setImage($image)
43 ->setDisplayHeight($display_height)
44 ->setDisplayWidth($display_width)
45 ->centerViewOnPoint(18, 18, 40, 80)
46 ->withMask(true);
47
48 $mask5 = id(new PHUIImageMaskView())
49 ->addClass('ml')
50 ->setImage($image)
51 ->setDisplayHeight($display_height)
52 ->setDisplayWidth($display_width)
53 ->centerViewOnPoint(254, 272, 60, 240)
54 ->withMask(true);
55
56 $box1 = id(new PHUIObjectBoxView())
57 ->setHeaderText(pht('Center is in the middle'))
58 ->appendChild($mask1);
59
60 $box2 = id(new PHUIObjectBoxView())
61 ->setHeaderText(pht('Center is on an edge'))
62 ->appendChild($mask2);
63
64 $box3 = id(new PHUIObjectBoxView())
65 ->setHeaderText(pht('Center Masked'))
66 ->appendChild($mask3);
67
68 $box4 = id(new PHUIObjectBoxView())
69 ->setHeaderText(pht('Edge Masked'))
70 ->appendChild($mask4);
71
72 $box5 = id(new PHUIObjectBoxView())
73 ->setHeaderText(pht('Wide Masked'))
74 ->appendChild($mask5);
75
76 return phutil_tag(
77 'div',
78 array(),
79 array(
80 $box1,
81 $box2,
82 $box3,
83 $box4,
84 $box5,
85 ));
86 }
87}