if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
* Elementor image widget.
* Elementor widget that displays an image into the page.
class Widget_Image extends Widget_Base {
* Retrieve image widget name.
* @return string Widget name.
public function get_name() {
* Retrieve image widget title.
* @return string Widget title.
public function get_title() {
return esc_html__( 'Image', 'elementor' );
* Retrieve image widget icon.
* @return string Widget icon.
public function get_icon() {
* Retrieve the list of categories the image widget belongs to.
* Used to determine where to display the widget in the editor.
* @return array Widget categories.
public function get_categories() {
* Retrieve the list of keywords the widget belongs to.
* @return array Widget keywords.
public function get_keywords() {
return [ 'image', 'photo', 'visual' ];
protected function is_dynamic_content(): bool {
* Get style dependencies.
* Retrieve the list of style dependencies the widget requires.
* @return array Widget style dependencies.
public function get_style_depends(): array {
return [ 'widget-image' ];
public function has_widget_inner_wrapper(): bool {
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
* Register image widget controls.
* Adds different input fields to allow the user to change and customize the widget settings.
protected function register_controls() {
$this->start_controls_section(
'label' => esc_html__( 'Image', 'elementor' ),
'label' => esc_html__( 'Choose Image', 'elementor' ),
'type' => Controls_Manager::MEDIA,
'url' => Utils::get_placeholder_image_src(),
$this->add_group_control(
Group_Control_Image_Size::get_type(),
'name' => 'image', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `image_size` and `image_custom_dimension`.
'label' => esc_html__( 'Caption', 'elementor' ),
'type' => Controls_Manager::SELECT,
'none' => esc_html__( 'None', 'elementor' ),
'attachment' => esc_html__( 'Attachment Caption', 'elementor' ),
'custom' => esc_html__( 'Custom Caption', 'elementor' ),
'label' => esc_html__( 'Custom Caption', 'elementor' ),
'type' => Controls_Manager::TEXT,
'placeholder' => esc_html__( 'Enter your image caption', 'elementor' ),
'caption_source' => 'custom',
'label' => esc_html__( 'Link', 'elementor' ),
'type' => Controls_Manager::SELECT,
'none' => esc_html__( 'None', 'elementor' ),
'file' => esc_html__( 'Media File', 'elementor' ),
'custom' => esc_html__( 'Custom URL', 'elementor' ),
'label' => esc_html__( 'Link', 'elementor' ),
'type' => Controls_Manager::URL,
'label' => esc_html__( 'Lightbox', 'elementor' ),
'type' => Controls_Manager::SELECT,
'description' => sprintf(
/* translators: 1: Link open tag, 2: Link close tag. */
esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
'<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
'default' => esc_html__( 'Default', 'elementor' ),
'yes' => esc_html__( 'Yes', 'elementor' ),
'no' => esc_html__( 'No', 'elementor' ),
$this->end_controls_section();
$this->start_controls_section(
'label' => esc_html__( 'Image', 'elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
$this->add_responsive_control(
'label' => esc_html__( 'Alignment', 'elementor' ),
'type' => Controls_Manager::CHOOSE,
'title' => esc_html__( 'Left', 'elementor' ),
'icon' => 'eicon-text-align-left',
'title' => esc_html__( 'Center', 'elementor' ),
'icon' => 'eicon-text-align-center',
'title' => esc_html__( 'Right', 'elementor' ),
'icon' => 'eicon-text-align-right',
'{{WRAPPER}}' => 'text-align: {{VALUE}};',
$this->add_responsive_control(
'label' => esc_html__( 'Width', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
'{{WRAPPER}} img' => 'width: {{SIZE}}{{UNIT}};',
$this->add_responsive_control(
'label' => esc_html__( 'Max Width', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
'{{WRAPPER}} img' => 'max-width: {{SIZE}}{{UNIT}};',
$this->add_responsive_control(
'label' => esc_html__( 'Height', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%', 'em', 'rem', 'vh', 'custom' ],
'{{WRAPPER}} img' => 'height: {{SIZE}}{{UNIT}};',
$this->add_responsive_control(
'label' => esc_html__( 'Object Fit', 'elementor' ),
'type' => Controls_Manager::SELECT,
'' => esc_html__( 'Default', 'elementor' ),
'fill' => esc_html__( 'Fill', 'elementor' ),
'cover' => esc_html__( 'Cover', 'elementor' ),
'contain' => esc_html__( 'Contain', 'elementor' ),
'scale-down' => esc_html__( 'Scale Down', 'elementor' ),
'{{WRAPPER}} img' => 'object-fit: {{VALUE}};',
$this->add_responsive_control(
'label' => esc_html__( 'Object Position', 'elementor' ),
'type' => Controls_Manager::SELECT,
'center center' => esc_html__( 'Center Center', 'elementor' ),
'center left' => esc_html__( 'Center Left', 'elementor' ),
'center right' => esc_html__( 'Center Right', 'elementor' ),
'top center' => esc_html__( 'Top Center', 'elementor' ),
'top left' => esc_html__( 'Top Left', 'elementor' ),
'top right' => esc_html__( 'Top Right', 'elementor' ),
'bottom center' => esc_html__( 'Bottom Center', 'elementor' ),
'bottom left' => esc_html__( 'Bottom Left', 'elementor' ),
'bottom right' => esc_html__( 'Bottom Right', 'elementor' ),
'default' => 'center center',
'{{WRAPPER}} img' => 'object-position: {{VALUE}};',
'object-fit' => [ 'cover', 'contain', 'scale-down' ],
'type' => Controls_Manager::DIVIDER,
$this->start_controls_tabs( 'image_effects' );
$this->start_controls_tab( 'normal',
'label' => esc_html__( 'Normal', 'elementor' ),
'label' => esc_html__( 'Opacity', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'{{WRAPPER}} img' => 'opacity: {{SIZE}};',
$this->add_group_control(
Group_Control_Css_Filter::get_type(),
'selector' => '{{WRAPPER}} img',
$this->end_controls_tab();
$this->start_controls_tab( 'hover',
'label' => esc_html__( 'Hover', 'elementor' ),
'label' => esc_html__( 'Opacity', 'elementor' ),
'type' => Controls_Manager::SLIDER,
'{{WRAPPER}}:hover img' => 'opacity: {{SIZE}};',
$this->add_group_control(
Group_Control_Css_Filter::get_type(),
'name' => 'css_filters_hover',
'selector' => '{{WRAPPER}}:hover img',
'background_hover_transition',