Advertisement
Ruslan_Rayanov

rs_webpImage

Dec 7th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.94 KB | None | 0 0
  1. ALTER   FUNCTION [dbo].[rs_webpImage]
  2. (      
  3.     @resourceID int,
  4.     @thumb bit = 0,
  5.     @alt nvarchar(max) ='',
  6.     @class nvarchar(64) = '',
  7.     @width nvarchar(20) = '',
  8.     @height nvarchar(20) = ''
  9. )
  10. RETURNS  nvarchar(256) as
  11. BEGIN
  12. declare @res nvarchar(256) = ''
  13.  
  14. declare  @url nvarchar(256) = (select iif(@thumb=1, thumbUrl, url) from as_rs_resources where id = @resourceID)
  15.  
  16. declare @webpUrl nvarchar(256) = replace(@url, reverse(left(reverse(@url), charindex('.', reverse(@url)) - 1)), 'webp')
  17.  
  18. declare @cl nvarchar(256) = iif(@class<>'', ' class="'+@class+'" ', '')
  19. declare @w nvarchar(256) = iif(@width<>'', ' width="'+@width+'" ', '')
  20. declare @h nvarchar(256) = iif(@height<>'', ' height="'+@height+'" ', '')
  21.  
  22. set @res = '
  23. <pic'+'ture'+@cl+'>
  24.     <so'+'urce srcset="'+@webpUrl+'" type="image/webp" loading="lazy" alt="'+@alt+'" '+@w+' '+@h+'>
  25.     <i'+'mg src="'+@url+'" alt="'+@alt+'" '+@w+' '+@h+'>
  26. </pict'+'ure>
  27. '
  28. return lower(@res)
  29. END
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement