php图片抖动,给网页添加图片抖动效果源码网站图片抖动怎么实现

今天发现在某个网站发现一个非常有意思的事情。就是把鼠标放在图片上面的时候图片会抖动。感觉非常有意思,去网上找了下资料,发现实现的方法非常有意思而且很简单。下面就说下怎么实现网页图片抖动的效果。

给ZBlog博客模版添加图片选中抖动效果

f4417823b8bb0999f110e4d0959fbfae.png

如何给网站图片添加抖动动态效果。把下面的CSS代码放在网站模版的CSS文件里面,一般是style.CSS,一般是所以网站都是通用的。

img:hover {

-webkit-animation:sucaijiayuan 1s .1s ease both;

-moz-animation:tada 1s .1s ease both;

}

@-webkit-keyframes sucaijiayuan {

0% {

-webkit-transform:scale(1)

}

10%, 20% {

-webkit-transform:scale(0.8) rotate(-2deg)

}

30%, 50%, 70%, 90% {

-webkit-transform:scale(1.1) rotate(2deg)

}

40%, 60%, 80% {

-webkit-transform:scale(1.1) rotate(-2deg)

}

100% {

-webkit-transform:scale(1) rotate(0)

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是Floyd-Steinberg抖动算法的C语言实现源码讲解: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" int main(int argc, char *argv[]) { if(argc < 2) { printf("Usage: %s <input-file>\n", argv[0]); return 1; } char* input_file = argv[1]; int width, height, channels; unsigned char* image_data = stbi_load(input_file, &width, &height, &channels, 0); if(image_data == NULL) { printf("Failed to load image: %s\n", input_file); return 1; } int** pixels = (int**)malloc(sizeof(int*) * width); for(int i = 0; i < width; i++) { pixels[i] = (int*)malloc(sizeof(int) * height); memset(pixels[i], 0, sizeof(int) * height); } for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { int index = (y * width + x) * channels; int oldPixel = (int)floor(0.2126 * image_data[index] + 0.7152 * image_data[index+1] + 0.0722 * image_data[index+2]); int newPixel = oldPixel > 127 ? 255 : 0; pixels[x][y] = newPixel; int error = oldPixel - newPixel; if(x < width - 1) { pixels[x+1][y] += (int)(error * 7 / 16.0); } if(x > 0 && y < height - 1) { pixels[x-1][y+1] += (int)(error * 3 / 16.0); } if(y < height - 1) { pixels[x][y+1] += (int)(error * 5 / 16.0); } if(x < width - 1 && y < height - 1) { pixels[x+1][y+1] += (int)(error * 1 / 16.0); } } } stbi_image_free(image_data); unsigned char* result_data = (unsigned char*)malloc(sizeof(unsigned char) * width * height); for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { result_data[y * width + x] = (unsigned char)pixels[x][y]; } } for(int i = 0; i < width; i++) { free(pixels[i]); } free(pixels); char* output_file = "output.png"; stbi_write_png(output_file, width, height, 1, result_data, width); free(result_data); printf("Image saved to: %s\n", output_file); return 0; } ``` 以上代码中,使用了stb_image和stb_image_write库来读取和保存图片文件。在实现过程中,首先使用二维数组存储每个像素点的值。对于每个像素点,根据其RGB值计算灰度值,并判断是否大于阈值,若大于则将其像素值设为255,否则设为0。然后计算误差并将其传递给周围的像素点,具体地,将误差按照一定的比例分配给周围的4个像素点,以实现误差扩散的效果。最后将处理后的像素点重新转换为unsigned char类型并保存为PNG格式的图片文件。 注意,在实现过程中需要注意防止越界访问,以及内存的释放等问题。 希望这份源码讲解对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值