Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
6b9ec9a1
Commit
6b9ec9a1
authored
1 year ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
allow imageproxy to scale down images and make jpegs progressive
parent
9032b2bf
No related branches found
Branches containing commit
No related tags found
3 merge requests
!2161
Translated using Weblate (Spanish)
,
!2152
Development
,
!2151
Resolve "Overhaul Imagesearch"
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
build/fpm/Dockerfile
+5
-4
5 additions, 4 deletions
build/fpm/Dockerfile
metager/app/Http/Controllers/Pictureproxy.php
+30
-10
30 additions, 10 deletions
metager/app/Http/Controllers/Pictureproxy.php
with
35 additions
and
14 deletions
build/fpm/Dockerfile
+
5
−
4
View file @
6b9ec9a1
...
...
@@ -17,18 +17,19 @@ RUN groupadd -g ${GID} metager && \
chown
${
UID
}
:
${
GID
}
/home/metager
# Install required php modules
RUN
apt update
&&
apt
install
-y
\
RUN
apt update
&&
apt
install
--no-install-recommends
-y
\
libzip-dev
\
libpng-dev
\
libfreetype-dev
\
libjpeg62-turbo-dev
\
libzstd-dev
\
libpq-dev
libpq-dev
\
libmagickwand-dev
RUN
docker-php-ext-configure gd
--with-freetype
--with-jpeg
RUN
docker-php-ext-install zip gd pcntl pdo_mysql pdo_pgsql
RUN
yes
'y'
| pecl
install
xdebug-3.2.2 igbinary-3.2.14 redis-5.3.7
RUN
docker-php-ext-enable igbinary redis
RUN
yes
'y'
| pecl
install
xdebug-3.2.2 igbinary-3.2.14 redis-5.3.7
imagick
RUN
docker-php-ext-enable igbinary redis
imagick
RUN
docker-php-ext-enable
--ini-name
=
xdebug.ini xdebug
# Add working dir for the code base
...
...
This diff is collapsed.
Click to expand it.
metager/app/Http/Controllers/Pictureproxy.php
+
30
−
10
View file @
6b9ec9a1
...
...
@@ -21,6 +21,8 @@ class Pictureproxy extends Controller
'data'
=>
'required'
,
]);
$thumbnail_width
=
$request
->
input
(
"thumbnail_width"
,
null
);
if
(
$validator
->
fails
())
{
abort
(
404
);
}
...
...
@@ -33,38 +35,42 @@ class Pictureproxy extends Controller
$validator
=
Validator
::
make
(
$input_data
,
[
'expires'
=>
'required|after_or_equal:now'
,
'url'
=>
'required|url'
,
'url'
=>
'required|url'
,
]);
if
(
$validator
->
fails
())
{
abort
(
404
);
}
$image_hash
=
md5
(
$input_data
[
"url"
]);
$image_hash
=
md5
(
$input_data
[
"url"
]
.
$thumbnail_width
);
if
(
Cache
::
has
(
$image_hash
))
{
$response
=
Cache
::
get
(
$image_hash
);
}
else
{
try
{
$url
=
$input_data
[
"url"
];
$file
=
file_get_contents
(
$url
,
false
);
$file
=
file_get_contents
(
$url
,
false
);
$responseCode
=
explode
(
" "
,
$http_response_header
[
0
])[
1
];
$contentType
=
""
;
$contentType
=
""
;
foreach
(
$http_response_header
as
$header
)
{
if
(
strpos
(
$header
,
"Content-Type:"
)
===
0
)
{
$tmp
=
explode
(
": "
,
$header
);
$tmp
=
explode
(
": "
,
$header
);
$contentType
=
$tmp
[
1
];
}
}
if
(
stripos
(
$contentType
,
"image/"
)
===
false
)
{
$finfo
=
new
\finfo
(
FILEINFO_MIME_TYPE
);
$finfo
=
new
\finfo
(
FILEINFO_MIME_TYPE
);
$contentType
=
$finfo
->
buffer
(
$file
);
}
if
(
stripos
(
$contentType
,
"image/"
)
===
false
)
{
abort
(
404
);
}
if
(
$contentType
===
"image/jpeg"
)
{
$file
=
$this
->
processJPEG
(
$file
,
$thumbnail_width
);
}
$response
=
Response
::
make
(
$file
,
$responseCode
,
[
'Content-Type'
=>
$contentType
,
'Content-Type'
=>
$contentType
,
"Cache-Control"
=>
"max-age=3600, must-revalidate, public"
,
"Last-Modified"
=>
gmdate
(
"D, d M Y H:i:s T"
),
]);
...
...
@@ -76,11 +82,25 @@ class Pictureproxy extends Controller
return
$response
;
}
private
function
processJPEG
(
string
$jpeg
,
$thumbnail_width
)
{
$src_image
=
new
\Imagick
();
$src_image
->
readImageBlob
(
$jpeg
);
$src_width
=
$src_image
->
getImageWidth
();
if
(
$thumbnail_width
!==
null
&&
$src_width
>
$thumbnail_width
)
{
$src_image
->
thumbnailImage
(
$thumbnail_width
,
0
);
}
$src_image
->
setInterlaceScheme
(
\Imagick
::
INTERLACE_PLANE
);
return
$src_image
->
getImageBlob
();
}
public
static
function
generateUrl
(
$link
)
{
$params
=
[
"url"
=>
$link
,
"expires"
=>
now
()
->
addDay
()
"url"
=>
$link
,
"expires"
=>
now
()
->
addDay
()
,
];
$params
=
Crypt
::
encrypt
(
$params
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment