diff --git a/includes/media.filter.inc b/includes/media.filter.inc index 4e9d64c..71d9e91 100644 --- a/includes/media.filter.inc +++ b/includes/media.filter.inc @@ -424,6 +424,41 @@ function media_get_file_without_label($file, $view_mode, $settings = array()) { } } + // Respect the width/height set in WYSIWYG editors by ensuring that all + // attributes and styles use the same values. + $height = $width = FALSE; + + // The logic goes: + // 1) Check to see if the user manually entered a style into the html or tinymce. + // 2) If not, use the height and width attributes. + // 3) If those aren't set, revert to the height and width that were already saved. + if(isset($settings['attributes'])) { + $width = isset($settings['width']) ? $settings['width'] : $settings['attributes']['width']; + $height = isset($settings['height']) ? $settings['height'] : $settings['attributes']['height']; + } + elseif (isset($element['#attributes'])){ + $width = isset($element['#attributes']['width']) ? $element['#attributes']['width'] : FALSE; + $height = isset($element['#attributes']['height']) ? $element['#attributes']['height'] : FALSE; + } + + if($width && $height) { + $element['#height'] = $height; + $element['#width'] = $width; + + if (!isset($settings['wysiwyg'])) { + $existing_styles = media_parse_css_declarations($element['#attributes']['style']); + $existing_styles['height'] = $height . 'px'; + $existing_styles['width'] = $width .'px'; + $styles = array(); + + foreach($existing_styles as $style_name=>$style_value) { + $styles[] = $style_name . ":" . $style_value; + } + + $element['#attributes']['style'] = implode(';', $styles); + } + } + return $element; }