public function generate_srcset_and_sizes( $image, $attachment_id ) {
		// Ensure the image meta exists.
		$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

		list( $image_src ) = explode( '?', $image_src );

		// Return early if we couldn't get the image source.
		if ( ! $image_src ) {
			return $image;
		}

		// Select image size from classname starting with 'size-'.
		$img_size = preg_match( '/ size-([^\s"]+)/', $image, $match_size ) ? $match_size[1] : false;

		// Bailout if image size couldn’t be read.
		if ( ! $img_size ) {
			return $image;
		}

		// Maybe select replacement size.
		if ( ! empty( $this->args['map_sizes'] ) ) {
			if ( is_array( $this->args['map_sizes'] )
				&& in_array( $img_size, array_keys( $this->args['map_sizes'] ), true )
			) {
				$img_size = $this->args['map_sizes'][ $img_size ];
			} else {
				$img_size = $this->args['map_sizes'];
			}
		}

		// Get responsive image markup for srcset and sizes.
		$attributes = get_timber_image_attributes_responsive(
			$attachment_id,
			$img_size
		);

		// Bailout if markup couldn’t be generated.
		if ( ! $attributes ) {
			return $image;
		}

		// Remove existing src
		$image = preg_replace( '/ src="([^"]+)"/', '', $image );

		/**
		 * Remove width, height and alt attributes, because they are handled by
		 * get_timber_image_responsive_src().
		 *
		 * @see get_timber_image_responsive_src()
		 */
		$image = preg_replace( '/ height="([^"]+)"/', '', $image );
		$image = preg_replace( '/ width="([^"]+)"/', '', $image );
		$image = preg_replace( '/ alt="([^"]+)"/', '', $image );
		$image = preg_replace( '/ title="([^"]+)"/', '', $image );

		// Remove class attribute and save class attribute content in attributes array.
		if ( preg_match( '/ class="([^"]+)"/', $image, $class_matches ) ) {
			$attributes['class'] = $class_matches[1];
			$image               = preg_replace( '/ class="([^"]+)"/', '', $image );
		}

		/**
		 * Filters image attributes used for a responsive content image.
		 *
		 * @param array  $attributes    A key-value array of HTML attributes.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$attributes = apply_filters(
			'timmy/responsive_content_image/attributes',
			$attributes,
			$attachment_id,
			$img_size
		);

		// Replace image markup
		$image = preg_replace(
			'/<img ([^>]+?)[\/ ]*>/',
			'<img $1 ' . Helper::get_attribute_html( $attributes ) . ' />',
			$image
		);

		/**
		 * Filters the image HTML markup.
		 *
		 * This filter can be used to append content to an image.
		 *
		 * @param string $image         The image HTML markup.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$image = apply_filters(
			'timmy/responsive_content_image',
			$image,
			$attachment_id,
			$img_size
		);

		return $image;
	}
public function generate_srcset_and_sizes( $image, $attachment_id ) {
		// Ensure the image meta exists.
		$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

		list( $image_src ) = explode( '?', $image_src );

		// Return early if we couldn't get the image source.
		if ( ! $image_src ) {
			return $image;
		}

		// Select image size from classname starting with 'size-'.
		$img_size = preg_match( '/ size-([^\s"]+)/', $image, $match_size ) ? $match_size[1] : false;

		// Bailout if image size couldn’t be read.
		if ( ! $img_size ) {
			return $image;
		}

		// Maybe select replacement size.
		if ( ! empty( $this->args['map_sizes'] ) ) {
			if ( is_array( $this->args['map_sizes'] )
				&& in_array( $img_size, array_keys( $this->args['map_sizes'] ), true )
			) {
				$img_size = $this->args['map_sizes'][ $img_size ];
			} else {
				$img_size = $this->args['map_sizes'];
			}
		}

		// Get responsive image markup for srcset and sizes.
		$attributes = get_timber_image_attributes_responsive(
			$attachment_id,
			$img_size
		);

		// Bailout if markup couldn’t be generated.
		if ( ! $attributes ) {
			return $image;
		}

		// Remove existing src
		$image = preg_replace( '/ src="([^"]+)"/', '', $image );

		/**
		 * Remove width, height and alt attributes, because they are handled by
		 * get_timber_image_responsive_src().
		 *
		 * @see get_timber_image_responsive_src()
		 */
		$image = preg_replace( '/ height="([^"]+)"/', '', $image );
		$image = preg_replace( '/ width="([^"]+)"/', '', $image );
		$image = preg_replace( '/ alt="([^"]+)"/', '', $image );
		$image = preg_replace( '/ title="([^"]+)"/', '', $image );

		// Remove class attribute and save class attribute content in attributes array.
		if ( preg_match( '/ class="([^"]+)"/', $image, $class_matches ) ) {
			$attributes['class'] = $class_matches[1];
			$image               = preg_replace( '/ class="([^"]+)"/', '', $image );
		}

		/**
		 * Filters image attributes used for a responsive content image.
		 *
		 * @param array  $attributes    A key-value array of HTML attributes.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$attributes = apply_filters(
			'timmy/responsive_content_image/attributes',
			$attributes,
			$attachment_id,
			$img_size
		);

		// Replace image markup
		$image = preg_replace(
			'/<img ([^>]+?)[\/ ]*>/',
			'<img $1 ' . Helper::get_attribute_html( $attributes ) . ' />',
			$image
		);

		/**
		 * Filters the image HTML markup.
		 *
		 * This filter can be used to append content to an image.
		 *
		 * @param string $image         The image HTML markup.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$image = apply_filters(
			'timmy/responsive_content_image',
			$image,
			$attachment_id,
			$img_size
		);

		return $image;
	}
public function generate_srcset_and_sizes ( $ image , $ attachment_id ) { // Ensure the image meta exists. $ image_src = preg_match ( '/src="([^"]+)"/' , $ image , $ match_src ) ? $ match_src [ 1 ] : '' ; list ( $ image_src ) = explode ( '?' , $ image_src ) ; // Return early if we couldn't get the image source. if ( ! $ image_src ) { return $ image ; } // Select image size from classname starting with 'size-'. $ img_size = preg_match ( '/ size-([^\s"]+)/' , $ image , $ match_size ) ? $ match_size [ 1 ] : false ; // Bailout if image size couldn’t be read. if ( ! $ img_size ) { return $ image ; } // Maybe select replacement size. if ( ! empty ( $ this -> args [ 'map_sizes' ] ) ) { if ( is_array ( $ this -> args [ 'map_sizes' ] ) && in_array ( $ img_size , array_keys ( $ this -> args [ 'map_sizes' ] ) , true ) ) { $ img_size = $ this -> args [ 'map_sizes' ] [ $ img_size ] ; } else { $ img_size = $ this -> args [ 'map_sizes' ] ; } } // Get responsive image markup for srcset and sizes. $ attributes = get_timber_image_attributes_responsive ( $ attachment_id , $ img_size ) ; // Bailout if markup couldn’t be generated. if ( ! $ attributes ) { return $ image ; } // Remove existing src $ image = preg_replace ( '/ src="([^"]+)"/' , '' , $ image ) ; /**
		 * Remove width, height and alt attributes, because they are handled by
		 * get_timber_image_responsive_src().
		 *
		 * @see get_timber_image_responsive_src()
		 */ $ image = preg_replace ( '/ height="([^"]+)"/' , '' , $ image ) ; $ image = preg_replace ( '/ width="([^"]+)"/' , '' , $ image ) ; $ image = preg_replace ( '/ alt="([^"]+)"/' , '' , $ image ) ; $ image = preg_replace ( '/ title="([^"]+)"/' , '' , $ image ) ; // Remove class attribute and save class attribute content in attributes array. if ( preg_match ( '/ class="([^"]+)"/' , $ image , $ class_matches ) ) { $ attributes [ 'class' ] = $ class_matches [ 1 ] ; $ image = preg_replace ( '/ class="([^"]+)"/' , '' , $ image ) ; } /**
		 * Filters image attributes used for a responsive content image.
		 *
		 * @param array  $attributes    A key-value array of HTML attributes.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */ $ attributes = apply_filters ( 'timmy/responsive_content_image/attributes' , $ attributes , $ attachment_id , $ img_size ) ; // Replace image markup $ image = preg_replace ( '/<img ([^>]+?)[\/ ]*>/' , '<img $1 ' . Helper :: get_attribute_html ( $ attributes ) . ' />' , $ image ) ; /**
		 * Filters the image HTML markup.
		 *
		 * This filter can be used to append content to an image.
		 *
		 * @param string $image         The image HTML markup.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */ $ image = apply_filters ( 'timmy/responsive_content_image' , $ image , $ attachment_id , $ img_size ) ; return $ image ; }
Updates image tag with responsive srcset and sizes attributes.

@param string $image         HTML image tag.
@param int    $attachment_id Attachment ID.

@return string Reponsive image markup
Updates image tag with responsive srcset and sizes attributes .