stocker4all / swift-html-image
This package is abandoned and no longer maintained.
No replacement package was suggested.
Embeds images in the html of a Swift Mailer Message body
v0.3
2017-10-31 14:31 UTC
Requires
- php: >=7.1
- swiftmailer/swiftmailer: >=5.4.8
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is not auto-updated.
Last update: 2024-01-24 20:10:41 UTC
README
swift-html-image
is a very simple solution to auto-embed image sources with a relative path inside html for further use in Swift Mailer Message.
For example:
<html> <title>stocker4all/swift-html-image</title> <body> <h1>swift-html-image</h1> <img src = "img/example.jpg"> <img src = "//example.com/example.jpg"> <img src = "http://example.com/example.jpg"> <img src = "https://example.com/example.jpg"> </body> </html>
Will be converted into something similar like this:
<html> <title>swift-html-image</title> <body> <h1>swift-html-image</h1> <img src="cid:cbb8136c77eade53667df53661e2a973@localhost"> <img src="//example.com/example.jpg"> <img src="http://example.com/example.jpg"> <img src="https://example.com/example.jpg"> </body> </html>
Note that only the image with the relative path has become a cid
value as source.
If an image with relative path can not be found an SwiftHtmlImageException
will be thrown.
Installing
You can use Composer to add the package to your project:
{ "require": { "stocker4all/swift-html-image": "~0.3" } }
Usage example
$html = '<!-- Your HTML goes here -->'; $swiftMessage = new Swift_Message(); $swiftHtmlImage = new S4A\SwiftHtmlImage( '/path-to-your-image-root-folder' ); $swiftMessage->setBody( $swiftHtmlImage->embedImages($swiftMessage, $html), "text/html", "utf-8");
Tests
Some very basic tests are provided in the tests/
directory. Run them with composer install --dev && vendor/bin/phpunit
.
License
swift-html-image
is licensed under MIT