tacnoman / thumcno
为您的缩略图提供服务
Requires
- php: >=5.3.0
- codeception/codeception: ^2.2
- katzgrau/klogger: dev-master
- symfony/console: *
- vlucas/phpdotenv: ^2.4
This package is auto-updated.
Last update: 2024-09-13 11:04:51 UTC
README
Thumcno - 实时运行的 Tacno 缩略图生成器
先决条件
要使用 thumcno,您需要先安装 php-gd。
$ sudo apt-get install php-gd # Ubuntu $ sudo yum install php-gd # CentOs $ brew install php-gd # Mac OS
您还必须安装 composer。 [https://composer.php.ac.cn/]
安装
git clone git@github.com:tacnoman/thumcno.git cd thumcno composer install php thumcno config # Follow the instructions php thumcno serve
基于 timthumb: http://www.binarymoon.co.uk/projects/timthumb/
您可以使用于任何具有不同域的项目。
它是如何工作的?
有许多裁剪图片的解决方案。我喜欢 timthumb 的解决方案。请求发送到包含参数的 PHP 文件。裁剪在运行时发生并生成缓存文件。Thumcno 项目增加了对此的安全措施,并可用于多个项目。它非常容易使用!我会给你展示!
第一步
您需要添加您的自定义域。您可以运行
php thumcno domain:add img.mydomain.com
此命令将在 /app/apps 目录中生成一个名为 img.mydomain.com.ini 的文件。此文件包含此域的自定义配置(例如:缓存目录等)。这些参数将替换默认.ini 中的参数(您可以更改它)。
这是 default.ini。
; This document has default params
port = 80
debug_on = true ; Enable debug logging to web server error log. Remember to update this param in your app
debug_level = 1 ; Debug level 1 is less noisy and 3 is the most noisy
memory_limit = 30M ; Set PHP memory limit
block_external_leechers = false ; If the image or webshot is being loaded on an external site, display a red "No Hotlinking" gif.
display_error_messages = true ; Display error messages. Set to false to turn off errors (good for production websites)
allow_external = false ; Allow image fetching from external websites. Will check against ALLOWED_SITES if ALLOW_ALL_EXTERNAL_SITES is false
allow_external_sites = false ; Less secure.
file_cache_enabled = true ; Should we store resized/modified images on disk to speed things up?
file_cache_time_between_cleans = 86400 ; How often the cache is cleaned
file_cache_max_file_age = 86400 ; How old does a file have to be to be deleted from the cache
file_cache_suffix = .thumcno ; What to put at the end of all files in the cache directory so we can identify them
file_cache_prefix = null ; What to put at the beg of all files in the cache directory so we can identify them
file_cache_directory = cache ; Directory where images are cached. Left blank it will use the system temporary directory (which is better for security)
max_file_size = 10485760 ; 10 Megs is 10485760. This is the max internal or external file size that we'll process.
curl_timeout = 20 ; Timeout duration for Curl. This only applies if you have Curl installed and aren't using PHP's default URL fetching mechanism.
wait_between_fetch_errors = 3600; Time to wait between errors fetching remote file
; Browser caching
browser_cache_max_age = 864000 ; Time to cache in the browser
browser_cache_disable = false ; Use for testing if you want to disable all browser caching
; Image size and defaults
max_width = 1500 ; Maximum image width
max_height = 1500 ; Maximum image height
not_found_image = null ; Image to serve if any 404 occurs
error_image = '' ; Image to serve if an error occurs instead of showing error message
png_is_transparent = true; Define if a png image should have a transparent background color. Use False value if you want to display a custom coloured canvas_colour
default_q = 90 ; Default image quality. Allows overrid in timthumb-config.php
default_zc = 1 ; Default zoom/crop setting. Allows overrid in timthumb-config.php
default_f = null ; Default image filters. Allows overrid in timthumb-config.php
default_s = 0 ; Default sharpen value. Allows overrid in timthumb-config.php
default_cc = ffffff ; Default canvas colour. Allows overrid in timthumb-config.php
default_width = 100 ; Default thumbnail width. Allows overrid in timthumb-config.php
default_height = 100 ; Default thumbnail height. Allows overrid in timthumb-config.php
您只需要替换必要的部分。
在本地机器上查看工作情况
要查看本地机器上的情况,请运行以下命令
cd /path/to/thumcno
php thumcno config
php thumcno serve
使用 Docker 运行
docker run -it -p 8888:80 tacnoman/thumcno ./thumcno server
# Sharing folder
docker run -it -p 8888:80 -v /path/to/thumcno/apps:/app/apps -v /path/to/thumcno/example_images:/app/example_images tacnoman/thumcno ./thumcno server
使用 docker-compose
TODO THIS!
现在,打开您的浏览器并访问以下 URL
https://:8888/?src=/dubai.jpg&w=200&h=200&q=80
您将看到这个
可能的参数
此列表是您可以传递到 URL($_GET)中的参数
设置可能的大小
如果您没有设置大小,可能会出现大的安全问题!假设您的 URI 是这样的 <w>/<h>/<src>。黑客可以编写一个脚本来生成缓存的所有可能大小。但是,您可以在网站上定义要生成的大小。这很简单
; <your_domain>.ini
; Possible_sizes
[sizes]
thumb = 30x30
medium = 200x200
large = 800x800
现在,您只能生成 30x30、200x200 和 800x800 大小的缩略图。如果您不想在 URL 中显示大小,可以使用 style(如 Ruby 的 paperclip)。
样式将替换大小。此配置的示例是
; <your_domain>.ini [styles] medium = 500x500 big = 800x700
http://<domain>/?src=dubai.jpg&style=medium -> 无友好 URL。 http://<domain>/medium/dubai.jpg -> 考虑到友好 URL,其中 URI 为 /(?P<style>\w+)/(?P<src>(\w|-|\.)+)。
URL 友好
如果您想使用友好 URL,可以在 .ini 文件中设置参数,传递 URL 参数。您必须了解正则表达式。参数是 route,您可以使用与以下格式相同的相同 URL 参数
(?P<name_of_param>\regex)
ex: (?P<w>\d+) -> Regex for para w (width) accepting only integers values
Another example:
^\/(?P<w>\d+)x(?P<h>\d+)\/(?P<q>\d{1,3})\/?
/<width>x<height>/<quality>/?src=example_images/dubai.jpg
One more example:
^\/(?P<w>\d+)x(?P<h>\d+)\/(?P<q>\d{1,3})\/(?<src>[\w.-]+)?
/<width>x<height>/<quality>/<source.jpg>
https://:8080/200x200/80/dubai.jpg
Ps: If you don't set any params in your regex, you can pass like $_GET param.
错误
给我发电子邮件:<renatocassino@gmail.com>。