npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

smart-scale

v1.0.3

Published

You can intelligently resize your images and prevent distortion of certain parts of the image.

Downloads

6

Readme

update v1.0.3

Support image proportion scaling.

支持图片比例缩放

if your image is too big, you can set the ratio 0.5

如果你的图片分辨率太高,你可以将显示比例设置为比如0.5

  // The fifth parameter is the display ratio and default value is 1;
  // 第五个参数是显示比例,默认值是1;
  const smartScale = new SmartScale('/static/img/test.png', [[384,464],[820,900]],[[324,440]],canvas, 0.5)

  //  If you want to change the display scale after the image is displayed
  // 如果你想在图片显示后更改显示比例
  smartScale.setRatio(0.5)
  // No need to call resizeHandle
  // 不需要调用resizeHandle函数

Introduction 介绍

You can scale your picture and prevent distortion of certain parts of the image by a canvas.

你可以通过一个canvas元素来智能缩放你的图片,并且保持图片的某些部分不会变形.

example use in vue3.2

以下是在vue3.2的示例

<template>
  <canvas ref="canvasRef" id="resCanvas" height="300" width="500"></canvas>
</template>

<script setup lang="ts">
  import { ref, type Ref, onMounted, onUnmounted } from "vue";
  import * as lodash from 'lodash';
  import {SmartScale} from 'smart-scale';

  const canvasRef: Ref<HTMLCanvasElement | undefined> = ref();
  const resizeHandle : Ref< (()=> void) | undefined> = ref()

  onMounted(()=>{
    // You need make sure which pixels of picture can be scaled
    // 你需要明确你的图片哪些像素是可以被放缩的。
    // In test.png image, the range of 384 to 464 and 820 to 900 pixels horizontally can be scaled, and the range of 324 to 440 pixels vertically can be scaled.
    // 在test.png中,横向的384像素到464像素,820像素到900像素是可以被缩放的,纵向的324像素到440像素范围是可以被缩放的。
  const smartScale = new SmartScale('/static/img/test.png', [[384,464],[820,900]],[[324,440]],canvasRef.value!)
  resizeHandle.value = lodash.throttle(()=>{
    smartScale.resizeHandle()
  }, 50)
  window.addEventListener('resize', resizeHandle.value!)
  })

  onUnmounted(()=>{
  window.removeEventListener('resize', resizeHandle.value!)
  })
</script>

If you need to create animations, you may notice some jitter during the scaling process. This is because the frequency of your canvas scaling and the execution of your resizeHandle function are inconsistent. You can manually ensure that the canvas size changes and the resizeHandle function execution are consistent. The canvas size means canvas.style.height and width,not canvas.height and canvas.width Or don't use throttle

如果你需要做动画,你会发现缩放过程有些抖动,这是因为你的canvas缩放和你的resizeHandle函数执行频率不一致导致的。你可以手动将canvas的尺寸变动和resizeHandle函数执行保持一致。

这里canvas缩放尺寸变动指的是canvas样式的height和width而不是canvas属性的height,width。

或者不用节流函数

smart-scale