Skip to content

Simple function for parsing base64-encoded inline jpg images from html code and converting them to resized image files

License

Notifications You must be signed in to change notification settings

filbe/html-jpg-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

html-jpg-parser

Simple function for parsing base64-encoded inline jpg images from html code and converting them to resized image files

Description

string htmlImagesToFilesAndResize ( string $html, number $max_width, number $max_height )

Returns parsed HTML string with all inline base64 jpg images converted to image files with tags replaced by the ones that links to files. For example:

<img src="data:image/jpg;base64, [base64 string.....]" width="x" height="y">
<img src="data:image/jpg;base64, [base64 string.....]" width="xx" height="yy">
<img src="data:image/jpg;base64, [base64 string.....]" width="xxx" height="yyy">
[etc]

will be converted to

<img src="dl/1.jpg" width="x" height="y">
<img src="dl/2.jpg" width="xx" height="yy">
<img src="dl/3.jpg" width="xxx" height="yyy">
[etc]

It also generates 100px x 100px thumbnail images to dl/thumbnails/[imgname]. This is very handy if you need to build a simple HTML editor with php and you don't want to mess with inline jpg images. See and run the example to test its power!

Parameters

html

HTML string as is when handling data generated by browser in contenteditable element

max_width

Max image width; Image scales down to this point with the correct ratio

max_height

Max image height; if, after scaled down by max_width, height is still greater than max_height, the image will be scaled down more so that its height is equal to max_height

About

Simple function for parsing base64-encoded inline jpg images from html code and converting them to resized image files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages