Code Snippet to Convert New Images to WebP - Code Snippets - Mark Harris - Media Library WordPress

Sdílet
Vložit
  • čas přidán 27. 11. 2023
  • Thanks to Mark Harris.
    Code: codesnippets.cloud/snippet/Su...
    Code Snippet to Convert New Images to WebP - Code Snippets - Mark Harris - Media Library WordPress
    Get our Awesome 'How to Build an Elementor Website Course' - Lifetime Updates and access to New Modules at no extra cost: learn.websquadron.co.uk/
    Join our 'How to Start a Web Design Business' Course - and use strategies to grow, get clients, and generate recurring income: websquadron.co.uk/how-to-star...
    Book your 1-2-1 Consultation: websquadron.co.uk/socials
    We love to create - share - respond - and deliver.
    🧐 Learn with our Mastery Modules: websquadron.co.uk/web-design-...
    🔗 All of our Important Links: websquadron.co.uk/socials/
    😃 Join our Facebook Group: / 3309523509284305
    😃 Get Code Snippets Pro: r.freemius.com/10565/3304295/
    😃 Get Elementor Pro: be.elementor.com/visit/?bta=2...
    😃 Boost your CZcams Analysis: www.tubebuddy.com/websquadron
    👕 Get our Merchandise: websquadron.co.uk/merchandise
    🥹 Support us: paypal.me/Websquadron
    Hire us to work on your Website!
    💌 info@websquadron.co.uk
    👩‍💻 Visit websquadron.co.uk
  • Jak na to + styl

Komentáře • 87

  • @darrenmoore7224
    @darrenmoore7224 Před 8 měsíci +13

    That's pretty awesome (especially when clients keep uploading stupid-size images, even when you instruct them to do otherwise!) Cheers Imran and Mark.

  • @jaapvanthof
    @jaapvanthof Před 8 měsíci

    More than perfect. Saves a lot a time. Thanks for sharing!

  • @maggiegens7512
    @maggiegens7512 Před 8 měsíci

    thank you imran and mark for sharing ---- this is just great and awesome!

  • @andaransfashion-jg9tl
    @andaransfashion-jg9tl Před 8 měsíci +1

    Thank you Mark Harris and Imran...

  • @gabrielk5497
    @gabrielk5497 Před 8 měsíci +1

    Wowww! Awesome solution for clients that upload images at whatever format and resolution 😅!

  • @learnearn3166
    @learnearn3166 Před 8 měsíci

    Thank you, for the code. you have done my work half. Once again, Thanks a lot.

  • @ylyaskudratullayev
    @ylyaskudratullayev Před 8 měsíci

    Thank you Mark Harris and thank you Imran

  • @reinhardeschbach7910
    @reinhardeschbach7910 Před 8 měsíci

    Very helpful. Great that you shared this!

  • @bobdebolt3321
    @bobdebolt3321 Před 8 měsíci

    Thanks Mark Harris !!

  • @JRGWxRxZ
    @JRGWxRxZ Před 8 měsíci +1

    Thank Imran & Mark, it's a game changer specially for clients whose editing themself their site 😀

  • @teeoffgolfclub1219
    @teeoffgolfclub1219 Před 8 měsíci

    Thank you for sharing. Really appreciate it.

  • @dieuhaudotnet
    @dieuhaudotnet Před 8 měsíci

    You are the best! Thank you!!

  • @edywerder
    @edywerder Před 8 měsíci

    Thanks, Imran and Mark - It's like magic happens in my WordPress!!

  • @enocknyaribari241
    @enocknyaribari241 Před 8 měsíci

    Thanks Imran for sharing and Mark thanks big up for this code, one of the best snippet out there's! Cheers

    • @websquadron
      @websquadron  Před 8 měsíci

      This falls into the Game-Changer category for sure!

  • @danygingras7782
    @danygingras7782 Před 8 měsíci

    This is just fantastic !!!!

  • @mayanikolova8353
    @mayanikolova8353 Před 8 měsíci

    super helpful, thank you!!

  • @naabigaabdoulrazak1959
    @naabigaabdoulrazak1959 Před 8 měsíci

    That's amazing, thank you for sharing
    KEEP UP THE GREAT WORK ✌

  • @matthewscott6730
    @matthewscott6730 Před 7 měsíci

    This is a very awesome snippet!

  • @blaz667
    @blaz667 Před 8 měsíci

    Thank you!👍

  • @visualmodo
    @visualmodo Před 7 měsíci

    Thanks you so much for your video!

  • @jakubnorman
    @jakubnorman Před 8 měsíci

    Brilliant 💪

  • @sorentauberlassen
    @sorentauberlassen Před 8 měsíci

    Very very useful!

  • @dsuinfotech
    @dsuinfotech Před 8 měsíci

    Very helpful no need to use third party sites you saved hours

  • @christianlecuyer6380
    @christianlecuyer6380 Před 8 měsíci

    Great tip... In my test, it perform better than Bulk Resize
    Thanks

  • @Art-01
    @Art-01 Před 8 měsíci

    Thank u

  • @user-kx8xt9zu8j
    @user-kx8xt9zu8j Před 7 měsíci +1

    That's quite impressive

  • @aminvalipoor2061
    @aminvalipoor2061 Před 8 měsíci

    nice

  • @phkoon
    @phkoon Před 3 měsíci

    Ok, it's working, but for some reason, when testing with this particular image, the webp file is getting bigger than the original jpg file (JPG = 285 KB to WebP = 301KB)

  • @shazadmohammed925
    @shazadmohammed925 Před 8 měsíci

    Thanks guys! This snippet is awesome. I normally compress the image using PS. Is it possible to compress the image, so we can get an even smaller file size?

    • @websquadron
      @websquadron  Před 8 měsíci +1

      Maybe as we’re looking at other possibilities

  • @mareckis8922
    @mareckis8922 Před 8 měsíci

    Thank you so much Imran! Great job! One question: can we tweak settings in the output WebP file? In Bulk... we can set the quality and size. Is it possible here also?

    • @websquadron
      @websquadron  Před 8 měsíci

      That's part of Phase 2 with looking at what else we can do with it.

  • @HarryThomas_HMT3design
    @HarryThomas_HMT3design Před 8 měsíci

    This is awesome! Is there something that could be added to scale down the size (say to 1200px wide) as well?

    • @websquadron
      @websquadron  Před 8 měsíci

      We're looking at scale buttons too, though you could manually edit the scale inside WP

  • @elnicolino
    @elnicolino Před 8 měsíci

    Great ! (as usual:))
    Does it work with user that have images libraries connected via a plugin as envato elements or instant images ?
    When choosing an image from these connected librairies images are automatically downloaded in library.

    • @websquadron
      @websquadron  Před 8 měsíci +2

      To be honest, not tried that yet. Let us know what you find if you do test - but make sure you have a backup/staging site.

  • @DanZL1
    @DanZL1 Před 8 měsíci +1

    Thank you for sharing. However there are two vulnerabilities found in the code. Have they been fixed?
    AI Bot Comments:
    Potential vulnerability found : Arbitrary File Deletion
    Found on line : 20
    Code : unlink( $file_path )
    Vulnerable line : 29
    Code : $file_path = $upload['file']);
    Potential vulnerability found : Arbitrary File Deletion
    Found on line : 20
    Code : unlink( $file_path )
    Vulnerable line : 29
    Code : $file_path = $upload['file']);
    Found 2 vulnerabilities

    • @websquadron
      @websquadron  Před 8 měsíci +3

      Yes; that's about removing the original PNG or JPEG when added so that you don't get duplicated images in your File Manager.

  • @homelandsecuritytoday
    @homelandsecuritytoday Před 8 měsíci

    Just works ! thanks. q. Any insight on changing the old Twitter 'share button' icon in Elementor? thks

    • @websquadron
      @websquadron  Před 8 měsíci +1

      Currently just upload the X SVG Icon to use. fontawesome.com/icons/x-twitter?f=brands&s=solid

    • @homelandsecuritytoday
      @homelandsecuritytoday Před 8 měsíci

      @@websquadron as an icon yes thank you. But in "shared buttons" icons are by default..

  • @christopheleroux-owd1274
    @christopheleroux-owd1274 Před 7 měsíci

    Great ! Is that snippet converting all the images sizes generated ? (Medium, large, ...) Thank a lot for the answer !

    • @websquadron
      @websquadron  Před 7 měsíci +2

      Yes it does. I just tested by setting my Media Settings for Thumb, Medium, large, and after adding a PNG image, it created WebP versions in the File Manager for the other sizes.

    • @christopheleroux-owd1274
      @christopheleroux-owd1274 Před 7 měsíci

      So what a wonderful snippet ! Thanks a lot !@@websquadron

  • @TLCOnlineChannel
    @TLCOnlineChannel Před 8 měsíci

    Hi Imran, great find, but have you seen the two notices about the code from the Code Snippets AI Bot? Should we be careful.

    • @websquadron
      @websquadron  Před 8 měsíci

      Don't worry that's about removing the original PNG or JPEG when added so that you don't get duplicated images in your File Manager.

    • @TLCOnlineChannel
      @TLCOnlineChannel Před 8 měsíci

      Thank you, Imran. I have tested the code and it works really well Mark wrote a lovely code snippet. All the very best, John

  • @meisterleise
    @meisterleise Před 8 měsíci

    @WebSquadron Does not work on my hosting. What did you say in the video what could be the problem if it doesn't work? I couldn't understand it acoustically. On my hosting ImageMagick 6.9.10 is installed (if that is what you were talking about). Thank you! 😊

    • @websquadron
      @websquadron  Před 8 měsíci +1

      Check with your host as ImageMagick and/or GD will be needed. if you used any other WebP Converting Plugin does that work?

    • @meisterleise
      @meisterleise Před 8 měsíci

      @@websquadron Thanks for your answer! As I wrote: ImageMagick is installed, but it still doesn't work. Plugins that convert images I didn't test. What a pity. Thank you anyway.

  • @jh_chen
    @jh_chen Před 8 měsíci

    Can I add the code in the php function of a child theme? to avoid deleting the code when I update the main theme

  • @percsimihaly6814
    @percsimihaly6814 Před 7 měsíci

    Is it possible to add the IPTC fields of the original file (jpg) to the converted file in the database, or to get the wp_post ID of the new file?
    i try wp_get_attachment_metadata, but not working.

    • @websquadron
      @websquadron  Před 7 měsíci

      You may need to write custom SQL query to update the post metadata for the new WebP file with the IPTC data extracted from the original JPG. However, this approach requires caution to avoid corrupting the database.

    • @percsimihaly6814
      @percsimihaly6814 Před 7 měsíci

      @@websquadron I already knew this, I just thought there was an idea to include it in this snippet.

  • @AFreshDetail
    @AFreshDetail Před 7 měsíci

    Are there any potential drawbacks or risks associated with automatically converting all uploaded images to WebP format, especially considering compatibility issues or user preferences?

    • @websquadron
      @websquadron  Před 7 měsíci +1

      It's fine as the majority will use the browsers that support WebP.

    • @AFreshDetail
      @AFreshDetail Před 7 měsíci

      @@websquadron gracias 🤙🏼

  • @SpencerTaylorOnline
    @SpencerTaylorOnline Před 6 měsíci

    Is there another version of this script that converts the original image, serves it as a WebP, and saves the original, too?

    • @websquadron
      @websquadron  Před 6 měsíci

      I'll need to dig out a modified version that saves the original too

    • @DoubleBullet
      @DoubleBullet Před 5 měsíci

      @@websquadron In the code snippet at line 50, it says " // Optionally remove the original image @unlink( $file_path ); "
      If you comment this line of code it should keep the original image.

  • @arturo5050
    @arturo5050 Před 8 měsíci

    But whats happend it the users browers dont serve webp image it wont ben show

    • @websquadron
      @websquadron  Před 8 měsíci +1

      Almost all do, and the small minority that don't need to catch up. If you know that the client's target audience are likely to use a Non-WebP Compliant browser then consider if you should use WebP or an alternate 'auto format presenter' solution. Remember that just because a client uses an old machine/kit or a browser not ready for WebP - should you ignore 96%+ of the market?
      Plus - WebP is just about page speed rendering of images. It's good practice to consider it.
      caniuse.com/webp

  • @phkoon
    @phkoon Před 3 měsíci

    Would you happen to know why the converted file is resulting in a WebP bigger than the uploaded jpeg file?

    • @websquadron
      @websquadron  Před 3 měsíci +1

      The compression algorithms for JPEG and WebP handle different types of image content with varying efficiency. Some images, especially those with large areas of uniform colour or simple patterns, might compress more efficiently with JPEG.
      JPEG compression can introduce visible artifacts in areas with high colour variance. When converting such a JPEG to WebP, trying to maintain the perceived quality might result in a larger file size because WebP attempts to reduce these artifacts.
      WebP supports the inclusion of rich metadata, such as ICC profiles, Exif data, and XMP data. If a JPEG image has minimal metadata and it's converted to a WebP that preserves or adds extensive metadata, the resultant WebP file could be larger.
      WebP offers both lossy and lossless compression. A JPEG image converted to a lossless WebP can be significantly larger because the original JPEG's lossy compression may have reduced the file size by eliminating details that lossless WebP aims to preserve.

    • @phkoon
      @phkoon Před 3 měsíci

      @@websquadron fair enough, thank you very much!

  • @liborlepka4240
    @liborlepka4240 Před 8 měsíci

    "Could not update snippet. Request failed with status code 500" Any idea why?

    • @iconrana3297
      @iconrana3297 Před 8 měsíci

      Same issue here😢

    • @websquadron
      @websquadron  Před 8 měsíci

      This is usually related to the server. Does your host allow access to GD or Magick?
      The error message "Could not update snippet. Request failed with status code 500" typically indicates that there was an internal server error while trying to update or modify a snippet of code or content on a website or application.

    • @websquadron
      @websquadron  Před 8 měsíci

      This is usually related to the server. Does your host allow access to GD or Magick?
      The error message "Could not update snippet. Request failed with status code 500" typically indicates that there was an internal server error while trying to update or modify a snippet of code or content on a website or application.

  • @adied7725
    @adied7725 Před 7 měsíci

    How about Avif images?

    • @websquadron
      @websquadron  Před 7 měsíci

      Many browsers are not ready for that

  • @zikoxweb
    @zikoxweb Před 4 měsíci

    Anyone have problems with the code is not working thanks

    • @websquadron
      @websquadron  Před 4 měsíci

      Works for me.
      Does your host allow gzip?

    • @zikoxweb
      @zikoxweb Před 4 měsíci

      @@websquadron works fine but now stops working and the images doesn't show in the library

  • @marcoprofwebsitenl6484
    @marcoprofwebsitenl6484 Před 8 měsíci

    whit

  • @CustomSneakers
    @CustomSneakers Před 8 měsíci

    FYI......Just checked the code and saw this. "Potential vulnerability found"

    • @websquadron
      @websquadron  Před 8 měsíci +2

      It's to do with removing items when it loads the WebP and can still be used.

  • @akuswanto
    @akuswanto Před 8 měsíci

    Thank you Mark Harris and Imran...