Conditions | 6 |
Paths | 6 |
Total Lines | 38 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public function process($html) |
||
27 | { |
||
28 | $matches = []; |
||
29 | |||
30 | if (false === preg_match_all('/<img([^>]*) src="(?!http)([^"]*)"/', $html, $matches)) { |
||
31 | return $html; |
||
32 | } |
||
33 | |||
34 | if (null === $current = $this->extractor->getCurrent()) { |
||
35 | return $html; |
||
36 | } |
||
37 | |||
38 | list($strings, $attributes, $files) = $matches; |
||
39 | |||
40 | foreach ($strings as $index => $string) { |
||
41 | $file = $files[$index]; |
||
42 | |||
43 | $path = sprintf('%s%s%s', dirname($current['readme']), DIRECTORY_SEPARATOR, $file); |
||
44 | |||
45 | if (false === file_exists($path)) { |
||
46 | continue; |
||
47 | } |
||
48 | |||
49 | if (false === $info = getimagesize($path)) { |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | $data = sprintf('data:%s;base64,%s', $info['mime'], base64_encode(file_get_contents($path))); |
||
54 | |||
55 | $html = str_replace( |
||
56 | $string, |
||
57 | sprintf('<img%s style="max-width: 100%%" src="%s"', $attributes[$index], $data), |
||
58 | $html |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | return $html; |
||
63 | } |
||
64 | } |
||
65 |