无损压缩图片心得(二)
用户之前在发烧网参加的上传图片活动都没有经过无损压缩处理.想用脚本对一月内传上去的图片进行处理,但Amazon_S3服务集群上只能使用他们提供的一些简单的API.所以只能先down 下来,压缩处理后,再传上去覆盖原来的图片.
经过多次调试,最终写了个php的脚本对之进行处理:详见这里.
代码如下:
<span class="lnum"> 1: </span><?php
<span class="lnum"> 2: </span><span class="kwrd">function</span> compress_img ($source) {
<span class="lnum"> 3: </span> $exts = array(<span class="str">"png"</span>,<span class="str">"bmp"</span>,<span class="str">"gif"</span>,<span class="str">"pnm"</span>,<span class="str">"tiff"</span>);
<span class="lnum"> 4: </span> $start_time = strtotime(<span class="str">"-30 day"</span>);
<span class="lnum"> 5: </span> exec(<span class="str">"s3cmd ls s3://fever38-us-static/hotdeals/{$source}/ > ./tmp.txt"</span>);
<span class="lnum"> 6: </span> $rs = file(<span class="str">'./tmp.txt'</span>);
<span class="lnum"> 7: </span> 
<span class="lnum"> 8: </span> <span class="kwrd">foreach</span>($rs <span class="kwrd">as</span> $line) {
<span class="lnum"> 9: </span> $r = array_filter(explode(<span class="str">' '</span>, $line));
<span class="lnum"> 10: </span> <span class="kwrd">if</span>(!empty($r[0])){
<span class="lnum"> 11: </span> $r[0] = trim($r[0]);
<span class="lnum"> 12: </span> $time = strtotime($r[0]);
<span class="lnum"> 13: </span> }
<span class="lnum"> 14: </span> <span class="kwrd">if</span>(!empty($time) && $time >= $start_time){
<span class="lnum"> 15: </span> <span class="kwrd">if</span>(!empty($r[10])){
<span class="lnum"> 16: </span> $img = trim($r[10]);
<span class="lnum"> 17: </span> $path_info = pathinfo($r[10]);
<span class="lnum"> 18: </span> $ext = trim($path_info[<span class="str">"extension"</span>]);
<span class="lnum"> 19: </span> $file_name = strtolower(trim($path_info[<span class="str">"basename"</span>]));
<span class="lnum"> 20: </span> 
<span class="lnum"> 21: </span> exec(<span class="str">"s3cmd get "</span>.$img);
<span class="lnum"> 22: </span> exec(<span class="str">"cp {$file_name} /mnt/heisoo/s3/{$source}/"</span>);
<span class="lnum"> 23: </span> 
<span class="lnum"> 24: </span> <span class="kwrd">if</span> (in_array($ext,$exts)) {
<span class="lnum"> 25: </span> system(<span class="str">"/usr/bin/optipng -o5 "</span>.$file_name);
<span class="lnum"> 26: </span> }
<span class="lnum"> 27: </span> <span class="kwrd">if</span> ($ext == <span class="str">"jpg"</span> || $ext == <span class="str">"jpeg"</span>) {
<span class="lnum"> 28: </span> system(<span class="str">"/usr/bin/jpegoptim -o --strip-all "</span>.$file_name);
<span class="lnum"> 29: </span> }
<span class="lnum"> 30: </span> system(<span class="str">"s3cmd put {$file_name} {$img} --guess-mime-type --add-header 'Cache-Control:max-age=31536000' --add-header 'Expires: Thu, 01 Dec 2014 16:00:00 GMT' --acl-public"</span>);
<span class="lnum"> 31: </span> unlink($file_name);
<span class="lnum"> 32: </span> }
<span class="lnum"> 33: </span> }
<span class="lnum"> 34: </span> }
<span class="lnum"> 35: </span> 
<span class="lnum"> 36: </span> unlink(<span class="str">'./tmp.txt'</span>);
<span class="lnum"> 37: </span>}
<span class="lnum"> 38: </span> 
<span class="lnum"> 39: </span>compress_img(<span class="str">"promotion_main_pic"</span>);
<span class="lnum"> 40: </span>compress_img(<span class="str">"src_thumb"</span>);
<span class="lnum"> 41: </span>compress_img(<span class="str">"uploadImage"</span>);
<span class="lnum"> 42: </span>compress_img(<span class="str">"dialog_image"</span>);
<span class="lnum"> 43: </span>compress_img(<span class="str">"joinPicture"</span>);
<span class="lnum"> 44: </span>?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

With the popularity of Douyin short videos, user interactions in the comment area have become more colorful. Some users wish to share images in comments to better express their opinions or emotions. So, how to post pictures in TikTok comments? This article will answer this question in detail and provide you with some related tips and precautions. 1. How to post pictures in Douyin comments? 1. Open Douyin: First, you need to open Douyin APP and log in to your account. 2. Find the comment area: When browsing or posting a short video, find the place where you want to comment and click the "Comment" button. 3. Enter your comment content: Enter your comment content in the comment area. 4. Choose to send a picture: In the interface for entering comment content, you will see a "picture" button or a "+" button, click

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

King of Glory has launched the Let’s Go Together to Flower Season event. Players who participate in the event can receive free avatar frames and many gifts. The event has a time limit and provides players with a total of four levels. Today, the editor has brought you a guide to the Let’s Go to Flower Season event. Encyclopedia, I hope it can help everyone complete the level challenge. A guide to the King of Glory's "Going to the Flowering Season" event. King of Glory, "Going to the Flowering Season" activity introduction. How to play: 1. "Going to the Flowering Season" is a card-turning activity, and players need to turn over the cards to pass the level. 2. Players can turn over cards by completing tasks and obtaining flower dew during the event. 3. Every four clearance cards in the activity panel are connected into a line (including horizontal lines, vertical lines and diagonal lines) to pass a small level. 4. Every time you clear a level, you can get corresponding rewards, and you can also get additional rewards by helping your friends turn over cards. live

I found that the compressed package downloaded from a download website will be larger than the original compressed package after decompression. The difference is tens of Kb for a small one and several dozen Mb for a large one. If it is uploaded to a cloud disk or paid space, it does not matter if the file is small. , if there are many files, the storage cost will be greatly increased. I studied it specifically and can learn from it if necessary. Compression level: 9-Extreme compression Dictionary size: 256 or 384, the more compressed the dictionary, the slower it is. The compression rate difference is larger before 256MB, and there is no difference in compression rate after 384MB. Word size: maximum 273 Parameters: f=BCJ2, test and add parameter compression rate will be higher
