Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Converts a img tag to CSS style
- *
- * @access public
- * @param <type> $img
- * @return string css or empty string
- */
- public function convert_img_to_css( $img ) {
- if ( !is_string( $img ) && false !== stripos( '<img', $img ) ) {
- throw new Exception ( __METHOD__ . ' excpects a string containing a <img /> tag. Recieved a ' . gettype( $img ) );
- }
- /**
- * Match the img
- */
- preg_match( '/<img[^>]+/i', $img, $match );
- if ( sizeof( $match ) === 0 ) {
- throw new Exception ( __METHOD__ . ' first argument did not contain a valid <img /> tag' );
- }
- preg_match_all( '/([a-z]+)="(.*?)"/i', $match[0], $attr );
- $allowed = array(
- 'src' => 'background: url("%s") no-repeat top left;',
- 'width' => 'width: %spx;',
- 'height' => 'height: %spx;',
- );
- $style = '';
- /**
- * Fetch the corresponding HTML tag and add it to the style
- */
- for ( $i = 0; $i < sizeof( $attr[1] ); $i++ ) {
- /**
- * Check if its tags that might be relevant to our conversion
- */
- if ( array_key_exists($attr[1][$i], $allowed) ) {
- printf($allowed[$attr[1][$i]],$attr[2][$i]);
- //$style .= sprintf( $allowed[$attr[1][$i]], $attr[2][$i] );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement