Monday June 2, 2025
Home
|
Contact
|
Support
|
PHP... a powerful, flexible, fully supported, battle tested server side language ..
<<
Random Page
Programming
C/C++
C# (with .net)
Win32/Win64
RegEx
Markdown (.md)
Python (.py)
Batch (.bat)
Programming XBOX & 360
XDK Tuts
NonXDK Tuts
OpenXDK Tuts
XNA with C#
Tutorials
Win32/Win64
DirectX3D (DirectX)
Maths of 3D
ASM..10101
Java
Physics
Visual Studio
Vulkan
Graphics
LaTeX
Data Mining & Machine Learning
AI
Fractals
Dual-Quaternions
Shaders
Vertex & Pixel Asm
Cg
Effect Files (.fx)
GLSL (.glsl)
WGSL (.wgsl)
Executable File Formats
PE (.exe) Inside Out
XBOX (.xbe) Format
Android (.apk)
3D File Formats
Quake2 (.md2) Format
Quake3 (.md3) Format
Quake3 BSP (.bsp)
3DS Format (.3ds)
X DirectX (.x)
GLTF (.glTF/.glb)
...
Image Formats
Bitmap (.bmp)
JPEG (.jpg)
DirectX DDS
Flash SWF
PNG (.png)
GIF (.gif)
WebP (.webp)
...
Internet Programming
WinSock
PHP
JavaScript
WebGL
WebXR
Retro Games
WebGPU
WebNN
Projects
Misc Demos
Notebook
Pixels
TexLive (LaTeX)
Crosswords
eNotes
Media
Quotes
Evolve
HSK
Slides
Trending
WordSearch
Links
Recommended Books
Donations (PayPal)
Contact
Books
Amazon
PHP...
a powerful, flexible, fully supported, battle tested server side language ..
Overlay Images
Simple little function to generate versions of the image with an overlay in the corner (e.g., tick or a cross).
function
addShapeOverlay
(
$sourceImagePath
,
$shape
=
'tick'
,
$color
= [
0
,
200
,
0
],
$sizeFactor
=
0.15
) {
if (!
file_exists
(
$sourceImagePath
)) {
return
false
;
}
// Define cache directory
$cacheDir
=
'./cache/'
;
if (!
is_dir
(
$cacheDir
)) {
mkdir
(
$cacheDir
,
0777
,
true
);
}
$outputPath
=
$cacheDir
.
'overlay_'
.
basename
(
$sourceImagePath
);
// Load the image
$imageInfo
=
getimagesize
(
$sourceImagePath
);
$width
=
$imageInfo
[
0
];
$height
=
$imageInfo
[
1
];
switch (
$imageInfo
[
'mime'
]) {
case
'image/jpeg'
:
$image
=
imagecreatefromjpeg
(
$sourceImagePath
);
break;
case
'image/png'
:
$image
=
imagecreatefrompng
(
$sourceImagePath
);
break;
default:
return
false
;
}
// Define shape size based on the image size
$shapeSize
=
min
(
$width
,
$height
) *
$sizeFactor
;
$padding
=
$shapeSize
*
0.2
;
$xPosition
=
$width
- (
$shapeSize
+
$padding
);
// Move to right side
$yPosition
=
$padding
;
// Custom shape color
$shapeColor
=
imagecolorallocate
(
$image
,
$color
[
0
],
$color
[
1
],
$color
[
2
]);
// Draw selected shape
switch (
$shape
) {
case
'tick'
:
imageline
(
$image
,
$xPosition
,
$yPosition
+ (
$shapeSize
*
0.5
),
$xPosition
+ (
$shapeSize
*
0.4
),
$yPosition
+
$shapeSize
,
$shapeColor
);
imageline
(
$image
,
$xPosition
+ (
$shapeSize
*
0.4
),
$yPosition
+
$shapeSize
,
$xPosition
+
$shapeSize
,
$yPosition
,
$shapeColor
);
break;
case
'cross'
:
imageline
(
$image
,
$xPosition
,
$yPosition
,
$xPosition
+
$shapeSize
,
$yPosition
+
$shapeSize
,
$shapeColor
);
imageline
(
$image
,
$xPosition
,
$yPosition
+
$shapeSize
,
$xPosition
+
$shapeSize
,
$yPosition
,
$shapeColor
);
break;
case
'question'
:
imagearc
(
$image
,
$xPosition
+ (
$shapeSize
/
2
),
$yPosition
+ (
$shapeSize
/
2
),
$shapeSize
,
$shapeSize
,
10
,
200
,
$shapeColor
);
imageline
(
$image
,
$xPosition
+ (
$shapeSize
*
0.5
),
$yPosition
+ (
$shapeSize
*
0.8
),
$xPosition
+ (
$shapeSize
*
0.5
),
$yPosition
+
$shapeSize
,
$shapeColor
);
break;
case
'star'
:
$points
= [
$xPosition
+ (
$shapeSize
*
0.5
),
$yPosition
,
$xPosition
+ (
$shapeSize
*
0.6
),
$yPosition
+ (
$shapeSize
*
0.4
),
$xPosition
+
$shapeSize
,
$yPosition
+ (
$shapeSize
*
0.4
),
$xPosition
+ (
$shapeSize
*
0.7
),
$yPosition
+ (
$shapeSize
*
0.7
),
$xPosition
+ (
$shapeSize
*
0.8
),
$yPosition
+
$shapeSize
,
$xPosition
+ (
$shapeSize
*
0.5
),
$yPosition
+ (
$shapeSize
*
0.85
),
$xPosition
+ (
$shapeSize
*
0.2
),
$yPosition
+
$shapeSize
,
$xPosition
+ (
$shapeSize
*
0.3
),
$yPosition
+ (
$shapeSize
*
0.7
),
$xPosition
,
$yPosition
+ (
$shapeSize
*
0.4
),
$xPosition
+ (
$shapeSize
*
0.4
),
$yPosition
+ (
$shapeSize
*
0.4
)
];
imagefilledpolygon
(
$image
,
$points
,
count
(
$points
) /
2
,
$shapeColor
);
break;
}
// Save the modified image
imagepng
(
$image
,
$outputPath
);
imagedestroy
(
$image
);
return
$outputPath
;
}
// Usage Example
$modifiedImage
=
addShapeOverlay
(
"./cover.jpg"
,
"star"
, [
255
,
200
,
0
],
0.2
);
echo
"Overlay image saved at: "
.
$modifiedImage
;
Advert (Support Website)
Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.