• v0.3.1 34130def95

    v0.3.1 Stable

    pythonbynight released this 2025-11-21 18:04:50 +01:00 | 0 commits to main since this release

    Summary

    There was a bug when passing a directory as the source_path to the WebImage object. There was a validation step that was erroneously failing. This has been fixed.

    Fixes

    • check for valid source_path was failing in some instances
    • added test to valid source_path 😅
    • updated README
    • fixed some docstring typos
    Downloads
  • v0.3.0 4f8a0fd03b

    v0.3.0 Stable

    pythonbynight released this 2025-11-19 07:52:50 +01:00 | 6 commits to main since this release

    Summary

    In HTML, <img> tags are considered in inline-block elements. Some markdown to html parsers will render images within <p> tags, which makes it awkward if you're actually treating img tags like block elements.

    However, another approach is to wrap images in <picture> or <figure> elements. In order to do that, the HTMLWriter class and some of the properties had to be refactored to allow for this flexibility in the future. This will allow a user to choose whether they want their HTML rendered with or without those parent tags.

    As a result, using the SrcsetItem and Sizes properties directly will also give the user more control as to how the markup is rendered. It was still important to provide sensible defaults for these values so that for most use cases, using render on its own will suffice. But the option is there to be more surgical.

    Additionally, an option to add size mappings for the size keywords has been added. This makes it easier to set defaults for one-off image resizes. Note, passing a tuple of

    Features

    • Output file with html snippet can now be saved as md and html in addition to txt
    • Allow custom size mappings to be passed in for keyword scaling/resizing to override the default "small", "medium", "large", and "thumbnail" keywords. For example:
    # Passed as a tuple of (width, height)
    # If height is "auto", the image will scale to the give width
    # For example, (100, "auto") means the height will be scaled accordingly
    # On the other hand, (100, 100) will try to `fit` the image within the constraint
    
    size_mapping = {
    	"small": (100, 100),
    	"big": (1000, 1000),
    	"huge": (2400, 2400)
    }
    
    # Will render an image 2400 x 2400 pixels
    webimage.render(size="huge", size_mapping=size_mapping)
    
    • Allow for custom srcset and sizes attributes to be set with more control using custom properties. For example:
    from _scribe import HTMLWriter
    from webimage.properties import Sizes, MediaCondition, SrcsetItem
    
    srcset_item = SrcsetItem(
            prepend_path="/img/static/",
            image_name="my_image",
            width=600,
            img_format="jpg",
        )
    
        sizes = Sizes(
            media_conditions=[
                MediaCondition(
                    min_or_max_width="max",
                    width_of_window=800,
                    image_width=96,
                    image_unit="vw",
                ),
                MediaCondition(
                    min_or_max_width="max",
                    width_of_window=1200,
                    image_width=1200,
                    image_unit="px",
                ),
            ]
        )
        html_writer = HTMLWriter(
            srcset_items=[srcset_item],
            sizes=sizes,
        )
    
    # Renders the following
    """
    <img class="responsive-image"
      srcset=
      "
      /img/static/my_image.jpg 600w
      "
      src="/img/static/my_image.jpg"
      sizes="(max-width: 800px) 96vw,
    		 (max-width: 1200px) 1200px,
              97vw"
      alt="..."
    />
    """
    

    Fixes

    • Removed kwargs arguments from PIL methods used by Mage.transform
    • Removed unnecessary entry script in pyproject.toml
    • Updated docstrings for clarity
    • Removed redundant attribute (img_format) from HTMLWriter
    Downloads
  • v0.2.2 b52a7fcd98

    v0.2.2 Stable

    pythonbynight released this 2025-11-15 06:14:19 +01:00 | 16 commits to main since this release

    🧙‍♀️ WebImage 🧙‍♂️

    WebImage has appeared!

    Conjure responsive web images easily. Invoke snippets of the html to match the image renders.

    from webimage import WebImage
    
    src_path: Path = path/to/img.jpg
    
    webimg = WebImage(src_path=src_path)
    
    # Creates default set (3 total) of responsive images
    webimg.render()
    

    The render method will create 3 images from the original in sizes ranging from 200px wide to 800px wide (retaining aspect ratio). It will also produce html text to plug in to your website.

    It will look a little like this:

    <img class="webimage"
      srcset=
      "
        image_200w.png 200w,
        image_600w.png 600w,
        image_800w.png 800w
      "
      src="image_800w.png"
      sizes="(max-width: 800px) 96vw, 800px"
      alt="..."
    />
    

    Check out the README file for more info.

    Downloads