/** * @param string $input * @param string $output * @param string[] $logLevels * @dataProvider svgProvider */ public function testCorrect(string $input, string $output, array $logLevels = []) { $validator = new SVGValidator(); $validator->setLogger($this); $this->assertEquals($this->formatXML($output), $this->formatXML($validator->correct($input))); $this->assertEquals($logLevels, $this->logLevels); }
public function correct(string $input) : string { if ($this->type === 'image/svg+xml') { try { $validator = new SVGValidator(); $validator->setLogger($this->logger); $input = $validator->correct($input); } catch (SyntaxException $e) { throw new SyntaxException($this->generateErrorMessage(), 0, $e); } } if ($this->isWindows() && $this->type === 'image/svg+xml') { // IM_MOD_RL_svg_.dllを利用するとPHPがクラッシュするため $corrected = $input; } else { $imagick = new \Imagick(); try { $imagick->readImageBlob($input); } catch (\ImagickException $e) { throw preg_match('/`(PNG|JPEG|SVG)\'/u', $e->getMessage()) === 1 ? $e : new SyntaxException($this->generateErrorMessage(), 0, $e); } if (str_replace('/x-', '/', $imagick->getImageMimeType()) !== $this->type) { throw new SyntaxException($this->generateErrorMessage()); } if ($this->type === 'image/jpeg') { $this->convertExifToJFIF($imagick); } $this->checkSize($imagick); $corrected = $imagick->getImageBlob(); $imagick->clear(); } return $corrected; }