Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
09341e02
Commit
09341e02
authored
9 years ago
by
Bruno Nocera Zanette
Browse files
Options
Downloads
Patches
Plain Diff
Add Thumbnail Module to handle Thumbnail Creation
parent
29c2e5e6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/thumbnail/creation.rb
+68
-0
68 additions, 0 deletions
lib/thumbnail/creation.rb
lib/thumbnail/formats.rb
+27
-0
27 additions, 0 deletions
lib/thumbnail/formats.rb
with
95 additions
and
0 deletions
lib/thumbnail/creation.rb
0 → 100644
+
68
−
0
View file @
09341e02
module
Thumbnail
module
Creation
include
Formats
def
generate_thumbnail
(
input
,
filename
,
size
)
unless
accepted_formats
.
include?
File
.
extname
(
filename
)
return
default_thumbnail
else
thumbnail
=
thumbnail_path
(
filename
,
size
)
output
=
"
#{
root_dir
}#{
thumbnail
}
"
begin
if
accepted_video_formats
.
include?
File
.
extname
(
input
)
generate_video_thumbnail
(
input
,
output
,
size
)
else
generate_image_thumbnail
(
input
,
output
,
size
)
end
rescue
return
default_thumbnail
else
return
thumbnail
end
end
end
private
def
generate_video_thumbnail
(
input
,
output
,
size
)
movie
=
FFMPEG
::
Movie
.
new
(
input
)
frame
=
(
movie
.
duration
*
25
/
100
).
floor
movie
.
screenshot
(
output
,
{
seek_time:
frame
,
resolution:
size
},
preserve_aspect_ratio: :width
)
end
def
generate_image_thumbnail
(
input
,
output
,
size
)
# Read the image and resize it. The `change_geometry' method
# computes the new image geometry and yields to a block. The
# return value of the block is the return value of the method.
img
=
Magick
::
Image
.
read
(
input
)[
0
]
img
.
change_geometry!
(
size
)
{
|
cols
,
rows
|
img
.
thumbnail!
cols
,
rows
}
img
.
write
(
output
)
end
def
encode_hash_from
(
object
)
Digest
::
SHA1
.
hexdigest
object
end
def
thumbnail_path
(
filename
,
size
)
thumbnail_name
=
encode_hash_from
filename
thumbnail_path
=
"
#{
thumbnails_dir
}
/
#{
thumbnail_name
}
_
#{
size
}
.jpg"
end
def
default_thumbnail
@default_thumbnail
||=
"
#{
thumbnails_dir
}
/default_thumbnail.jpg"
end
def
thumbnails_dir
@thumbnails_dir
||=
"/thumbnails"
end
def
root_dir
@root_dir
||=
Rails
.
root
.
join
(
'public'
)
end
end
end
This diff is collapsed.
Click to expand it.
lib/thumbnail/formats.rb
0 → 100644
+
27
−
0
View file @
09341e02
module
Thumbnail
module
Formats
def
accepted_video_formats
lower
=
[
".mp4"
,
".wmv"
,
".3gp"
,
".asf"
,
".avi"
,
".flv"
,
".mov"
,
".mpg"
,
".mpeg"
,
".rmvb"
,
".vob"
,
".webm"
]
upper
=
[
".MP4"
,
".WMV"
,
".3GP"
,
".ASF"
,
".AVI"
,
".FLV"
,
".MOV"
,
".MPG"
,
".MPEG"
,
".RMVB"
,
".VOB"
,
".WEBM"
]
return
lower
+
upper
end
def
accepted_image_formats
lower
=
[
".jpg"
,
".jpeg"
,
".gif"
,
".png"
,
".bmp"
,
".tif"
]
upper
=
[
".JPG"
,
".JPEG"
,
".GIF"
,
".PNG"
,
".BMP"
,
".TIF"
]
return
lower
+
upper
end
def
accepted_other_formats
lower
=
[
".pdf"
,
".pps"
]
upper
=
[
".PDF"
,
".PPS"
]
return
lower
+
upper
end
def
accepted_formats
return
accepted_video_formats
+
accepted_image_formats
+
accepted_other_formats
end
end
end
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