ComusThumbz ドキュメント
管理者ログイン

Thumbscanner

Overview

The Turbo Cropper (thumbscan.php) is a comprehensive gallery thumbnail scanning and cropping utility. It fetches remote gallery pages, extracts images using advanced hybrid detection (regex + DOM), downloads them for preview, and provides an interactive cropping interface with star rating and text overlay capabilities. This tool is essential for creating high-quality thumbnails for imported gallery content.

[Screenshot: thumbscan-overview]


System Requirements

 

Configuration Required:
This page requires the following system dependencies to function properly.

 

PHP Requirements

Requirement Minimum Recommended Notes
PHP Version 8.0 8.2+ Required for strict types
memorylimit 256M 512M For image processing
maxexecutiontime 300 600 Extended for slow remote servers

Required PHP Extensions

Extension Required Purpose
GD Yes Image creation, cropping, and overlays
cURL Yes Fetching remote pages and images
mysqli Yes Database connectivity
json Yes Progress tracking and metadata
session Yes User authentication
libxml Yes DOM parsing for image detection

Required PHP Functions

Function Purpose
curlinit() HTTP requests for pages and images
curlmultiinit() Parallel image downloads
imagecreatefromstring() Image validation
imagecreatefromjpeg() JPEG processing
imagecreatetruecolor() Thumbnail creation
imagecopyresampled() High-quality image scaling
imagejpeg() JPEG output
imagettftext() TrueType font text overlays
filegetcontents() Image download fallback
fileputcontents() Progress file writing
Warning: The GD extension must have JPEG support enabled. For TTF text overlays, FreeType support is also required. Check with gdinfo() function.

External Tools

Tool Required Purpose
TrueType Fonts Optional Enhanced text overlays (arial.ttf, etc.)

Folder Permissions

Folder Permission Owner Purpose
ct/admin/temp/ 775 www-data Temporary image storage during scanning
ct/admin/temp/{galleryid}/ 775 www-data Per-gallery scan results
ct/thumbs/ 775 www-data Final thumbnail storage
ct/admin/fonts/ 755 www-data TrueType fonts for text overlays

Server Requirements

Component Requirement
Web Server Apache 2.4+ with modrewrite OR Nginx
Database MySQL 5.7+ / MariaDB 10.3+
Network Outbound HTTP/HTTPS for remote image fetching

Installation Requirements

Fonts Directory

For enhanced text overlays, place TrueType fonts in:

  • ct/admin/fonts/ (primary)
  • ct/fonts/ (fallback)

 

Supported font files:

Font Family Accepted Files
Arial arial.ttf, Arial.ttf, LiberationSans-Regular.ttf
Helvetica helvetica.ttf, arial.ttf
Times times.ttf, TimesNewRoman.ttf, LiberationSerif-Regular.ttf
Courier courier.ttf, cour.ttf, LiberationMono-Regular.ttf
Georgia georgia.ttf, Georgia.ttf
Verdana verdana.ttf, Verdana.ttf
Trebuchet trebuchet.ttf, trebuc.ttf
Comic Sans comic.ttf, comicsans.ttf
Note: If TTF fonts are not available, the system falls back to GD built-in bitmap fonts with reduced quality.

Features & UI Elements

Entry Page (No Gallery Selected)

[Screenshot: thumbscan-entry]

When accessed without a gallery ID:

Field Description
Page Index Gallery ID to scan (required)
Gallery URL Remote URL to scan for images (required)
Start Enhanced Scan Begin scanning with live progress

Enhanced Features Listed:

  • Real-time Progress Updates
  • Flexible Image Detection (regex + DOM hybrid)
  • Enhanced XPath Queries
  • Video Content Detection
  • Smart Error Handling
  • Debug Mode

Live Progress Page

[Screenshot: thumbscan-progress]

During scanning, shows:

Element Description
Progress Bar Visual percentage of completion
Status Badge Scanning, Complete, or Error
Images Found Number of potential images detected
Pages Scanned Pages processed
Target Images Maximum images to grab (default: 25)
Downloaded Successfully downloaded images
Scan Log Real-time scrolling log with colored entries
Continue Button Appears on completion to proceed to cropper

Cropping Interface

[Screenshot: thumbscan-cropping]

The main thumbnail creation interface:

Thumbnail Strip

[Screenshot: thumbscan-strip]

  • Horizontal scrollable grid of downloaded images
  • Maximum 40 images displayed (20 per row)
  • Size indicator below each thumbnail
  • Click to select as main image
  • Green border indicates selected image
  • Scroll buttons for navigation

Main Cropping Area

[Screenshot: thumbscan-main-crop]

Element Description
Source Image Full-size selected image with darkened filter
Crop Selection Box Green-bordered resizable selection area
Highlight Effect Selected area shows full brightness
Drag to Move Click and drag the selection box
Resize Drag edges or corners to resize

Live Preview Panel

[Screenshot: thumbscan-preview]

Real-time preview at exact thumbnail dimensions:

  • Shows current crop selection
  • Displays overlay effects (stars, text)
  • Updates instantly as you adjust

 

Star Rating Overlay

[Screenshot: thumbscan-stars]

Control Type Default Description
Enable star overlay Checkbox Off Toggle star rating display
Star Rating Interactive stars 5 Click to set 1-5 stars
Color Color picker #FFD700 (gold) Star fill color
Position Dropdown Bottom Right Star placement

Position Options:

  • Top Left, Top Right
  • Bottom Left, Bottom Right
  • Center

Text Overlay

[Screenshot: thumbscan-text]

Quick Text Buttons:

  • Up to 15 most frequently used text overlays
  • Category names as quick options
  • Click to instantly apply

 

Text Controls:

Control Options Default Description
Text Input Text field Empty Overlay text (max 50 chars)
Text Color Color picker #FFFFFF Text color
Font Family 8 fonts Arial Font face
Font Size 8-48 px 14 Text size
Font Weight Normal/Bold Normal Text weight
Rotation -180° to +180° Text rotation angle

Text Effects:

Control Type Default Description
Drop Shadow Checkbox Off Enable shadow effect
Shadow Color Color picker #000000 Shadow color
Shadow X Slider (-10 to 10) 2 Horizontal offset
Shadow Y Slider (-10 to 10) 2 Vertical offset
Shadow Blur Slider (0 to 10) 0 Blur radius
Outline Slider (0 to 5) 1 Text outline thickness

Text Position Options:

  • Top Left, Top Center, Top Right
  • Center Left, Center, Center Right
  • Bottom Left, Bottom Center, Bottom Right

Action Buttons

[Screenshot: thumbscan-actions]

Button Color Action
Capture Green Save thumbnail and close
Capture and NEXT Blue Save and move to next gallery without thumbnail
Disapprove Red Mark gallery as disapproved and move to next

User Instructions Panel

[Screenshot: thumbscan-instructions]

Collapsible panel showing:

  • Cropping instructions
  • Keyboard shortcuts
  • Overlay configuration tips

 

Keyboard Shortcuts:

Key Action
Arrow Keys Move crop selection
+/- Resize selection
Enter Submit/Capture thumbnail
Esc Cancel operation

Font Test Utility

[Screenshot: thumbscan-fonttest]

Accessed via ?action=fonttest:

  • Shows font directory status
  • Lists available TTF fonts
  • Displays font mapping status
  • Live font test generator
  • Test rotation, shadows, outlines

Step-by-Step Usage

  1. Navigate to Admin Panel → Database → Galleries → Review
  2. Find a gallery without a thumbnail
  3. Click the Create Thumbnail button or icon
  4. System redirects to thumbscan with gallery info

Using the Progress Page

  1. Scan begins automatically upon page load
  2. Watch the progress bar fill
  3. Monitor log entries for any issues
  4. Wait for "Scan Complete" status
  5. Click Continue to Cropping button

 

Tip: If scanning fails, check the log for specific errors. Common issues include: blocked URLs, missing images, or timeout errors.

 

Creating a Thumbnail

  1. Select Source Image: Click thumbnail in strip to use different image
  2. Position Crop Box: Drag the green selection to desired position
  3. Resize if Needed: Drag edges/corners to adjust aspect ratio
  4. Add Star Rating (optional):
  • Check "Enable star overlay"
  • Click desired star count (1-5)
  • Choose color and position
  1. Add Text Overlay (optional):
  • Check "Enable text overlay"
  • Enter text or click quick button
  • Configure font, size, color
  • Add shadow/outline effects
  1. Preview: Check the live preview panel
  2. Save: Click Capture or Capture and NEXT

Batch Processing Galleries

Using "Capture and NEXT" workflow:

  1. Process first gallery's thumbnail
  2. Click Capture and NEXT
  3. System automatically finds next gallery without thumbnail
  4. Page redirects to scan that gallery
  5. Repeat until all galleries have thumbnails
  6. "All Galleries Complete" message shows when done

If gallery images are unsuitable:

  1. Review the available images
  2. Click Disapprove button
  3. Gallery marked with accept='disapproved'
  4. System moves to next gallery automatically

Technical Details

Image Detection Pipeline

1. Fetch Page → cURL with retry logic (max 3 attempts)
  1. Parse HTML → Check for <base href> override
  2. Find Images:

   a. Regex extraction (href, src, srcset, data-src, etc.)
   b. Filter unwanted patterns (logos, icons, pixels)
   c. Priority scoring (prefer "full", "large" over "thumb")
  1. Resolve URLs:

   a. Protocol-relative (//example.com)
   b. Root-relative (/path/image.jpg)
   c. Page-relative (./image.jpg)
   d. Dual-domain resolution when base href differs

Download Images → Fast parallel downloadsValidate → Check size, content-type, GD compatibilityCreate Thumbnails → Generate preview versions

  1. Store Metadata → Save original URL and dimensions

Video Detection

The scanner automatically detects video galleries and sets hasvideo=1:

Detection Methods:

  1. <video> tags in DOM
  2. Video platform iframes (YouTube, Vimeo, PornHub, etc.)
  3. Video file extensions (.mp4, .webm, .m4v, etc.)
  4. <source> tags with video MIME types
  5. Video player JavaScript references (jwplayer, videojs, etc.)
  6. HLS/DASH streaming manifests (.m3u8, .mpd)

 

URL Resolution Logic

function resolveUrl($relativeUrl, $baseUrl) {
    // Already absolute → return as-is
    // Protocol-relative (//example.com) → add scheme
    // Root-relative (/path) → add domain
    // Page-relative (./path or path) → add base path
    // Handle ../ navigation
}

Progress Tracking

Progress stored in JSON files:

ct/admin/temp/scanprogress{galleryid}.json

 

Content:

{

  "status": "scanning",

  "totaltarget": 25,

  "currentimages": 15,

  "pagesscanned": 1,

  "imagesfound": 30,

  "imagesdownloaded": 15,

  "logs": ["12:34:56 - Starting scan..."],

  "timestamp": 1704067200

}

 

Thumbnail Generation

// Create destination canvas
$desim = imagecreatetruecolor($thumbwidth, $thumbheight);

// Extract crop region
$tmpim = imagecreatetruecolor($capturewidth, $captureheight);
imagecopy($tmp
im, $srcim, 0, 0, $captureX, $captureY, $capturewidth, $captureheight);


// Resample to final size
imagecopyresampled($des
im, $tmpim, 0, 0, 0, 0, $thumbwidth, $thumbheight, $capturewidth, $captureheight);


// Apply overlays
addStarsOverlay($des
im, ...);
addTextOverlay($desim, ...);


// Save files
imagejpeg($des
im, $thumbfile, $quality); // Display version
imagejpeg($des
im, $thumbmasterfile, 100); // Master copy

 

File Naming

File Location Purpose
tn{id}.jpg ct/thumbs/ Display thumbnail
tn{id}.jpg ct/thumbs/ Master copy (100% quality)
{nnn}.jpg ct/admin/temp/{id}/ Downloaded source images
{nnn}.jpg ct/admin/temp/{id}/ Preview thumbnails
{nnn}.meta ct/admin/temp/{id}/ Image metadata JSON

Troubleshooting

Scan Fails to Start

 

Error:
Error: "ERR: Bad pageindex value"

 

The gallery ID is missing or invalid.

Solutions:

  1. Ensure gallery ID is a valid integer
  2. Access via gallery list (don't manually enter URL)
  3. Check gallery exists in tblTgp

 

No Images Found

 

Error:
Error: "No valid thumbnail images were found"

 

The remote page has no extractable images.

Solutions:

  1. Verify the gallery URL is accessible
  2. Check if site blocks automated access
  3. Some sites use JavaScript-loaded images (not supported)
  4. Try a different gallery from the same source
  5. Review scan log for specific errors

 

Image Download Fails

 

Warning:
Warning: "HTTP 403" or "HTTP 404" errors

 

Remote server blocking or images moved.

Solutions:

  1. Site may block hotlinking
  2. Images may have been removed
  3. Try scanning from gallery homepage instead
  4. Check if source requires authentication

 

Cropping Interface Not Loading

 

Warning:
Warning: Images show but cropper doesn't appear

 

JavaScript error or missing elements.

Solutions:

  1. Check browser console for JavaScript errors
  2. Refresh the page
  3. Clear browser cache
  4. Ensure showcropper=1 in URL
  5. Verify temp images exist

 

Text Overlay Not Appearing

 

Error:
Error: Text shows in preview but not on saved thumbnail

 

Font files missing or GD issues.

Solutions:

  1. Verify TTF fonts exist in ct/admin/fonts/
  2. Check font file permissions (readable)
  3. Use Font Test utility (?action=fonttest)
  4. Check PHP error logs for GD errors
  5. Falls back to built-in fonts if TTF missing

 

Stars Not Displaying

 

Warning:
Warning: Stars checkbox enabled but stars don't appear

 

Overlay settings not syncing.

Solutions:

Verify star count > 0Check star color isn't same as background
  1. Ensure starsenabled checkbox is checked
  2. Review browser console for JavaScript errors

 

Thumbnail Not Saving

 

Error:
Error: "Failed to save thumbnail"

 

Cannot write to thumbs directory.

Solutions:

mkdir -p ct/thumbs

chmod 775 ct/thumbs

chown www-data:www-data ct/thumbs

 

Database Update Failed

 

Error:
Error: "Database update failed"

 

Cannot update tblTgp record.

Solutions:

  1. Check database connection
  2. Verify gallery ID exists
  3. Check user permissions on table
  4. Review MySQL error logs

 

Scan Takes Too Long

 

Warning:
Warning: Progress stuck or very slow

 

Remote server slow or many images.

Solutions:

  1. Reduce thumbstograb count (default 25)
  2. Check remote server response time
  3. Increase PHP maxexecutiontime
  4. Check network connectivity
  5. Some servers rate-limit requests

 


AJAX Endpoints

progress

Gets current scan progress:

  • Method: GET
  • Parameters: action=progress, pageindex={galleryid}
  • Returns: Progress JSON object

 

startscan

Initiates background scanning:

  • Method: GET
  • Parameters: startscan=1, pageindex={galleryid}, url={galleryurl}
  • Returns: Completion JSON when done

 

capture / captureandnext

Saves thumbnail and updates database:

  • Method: POST
  • Parameters: Form data including crop coordinates, overlay settings
  • Returns: Success page with thumbnail preview

 

disapprove

Marks gallery as disapproved:

Method: POST

  • Parameters: action=disapprove, pageindex={galleryid}
  • Returns: Redirect to next gallery

 

keepthumb

Uses existing thumbnail with overlays:

  • Method: POST
  • Parameters: Form data with overlay settings
  • Returns: Success page with updated thumbnail

 

fonttest

Font detection utility:

  • Method: GET
  • Parameters: action=fonttest
  • Returns: Font test HTML page

 


Page Purpose
admin.php Gallery review list
aicrop.php AI-powered thumbnail cropper
aigalleryreview.php AI gallery analysis
comus.add.php Gallery bulk import

Translatable Strings

The following text strings appear in this page and should be added to backendtranslations.md:

Page Titles

  • "Enhanced Thumbscan with Real-time Progress"
  • "Enhanced Comus Thumbnail Cropper"
  • "Thumbnail Saved Successfully!"
  • "All Galleries Complete!"
  • "Scan Error"

Progress Page

  • "Initializing..."
  • "Scanning..."
  • "Scan Complete"
  • "Scan Error"
  • "Images Found"
  • "Pages Scanned"
  • "Target Images"
  • "Downloaded"
  • "Scan Log"
  • "Continue to Cropping"
  • "Return to Admin"

Cropping Interface

  • "PLEASE WAIT FOR SCAN TO 100% COMPLETE"
  • "Visit Url"
  • "Select thumbnail to crop"

Overlay Controls

  • "Star Rating Overlay"
  • "Enable star overlay"
  • "Color:"
  • "Position:"
  • "Top Left"
  • "Top Right"
  • "Bottom Left"
  • "Bottom Right"
  • "Center"

Text Overlay

  • "Text Overlay"
  • "Enable text overlay"
  • "Quick Text:"
  • "Enter text..."
  • "Font Family:"
  • "Font Size:"
  • "Font Weight:"
  • "Rotation (°):"
  • "Normal"
  • "Bold"

Text Effects

  • "Text Effects"
  • "Drop Shadow"
  • "Shadow X:"
  • "Shadow Y:"
  • "Blur:"
  • "Outline:"

Font Families

  • "Arial"
  • "Helvetica"
  • "Times New Roman"
  • "Courier"
  • "Georgia"
  • "Verdana"
  • "Trebuchet MS"
  • "Comic Sans"

Action Buttons

  • "Capture"
  • "Capture and NEXT"
  • "Disapprove"
  • "Return to Review Editor"
  • "Close Window"

Status Messages

  • "Moving to next gallery that needs a thumbnail..."
  • "Next Gallery ID:"
  • "URL:"
  • "Please wait, we are scanning the next gallery URL..."
  • "Wrapping Around to Beginning"
  • "No more galleries found after current ID."
  • "Database Statistics:"
  • "Total Galleries:"
  • "With Thumbnails:"
  • "Without Thumbnails:"
  • "No URL:"

Error Messages

  • "ERR: Bad pageindex value"
  • "ERR: Bad record"
  • "ERROR! Invalid page index!"
  • "ERROR! GD library is not available."
  • "ERROR! Source image not found."
  • "ERROR! Failed to create thumbs directory."
  • "ERROR! Thumbs directory is not writable."
  • "ERROR! GD processing failed:"
  • "ERROR! Database update failed:"
  • "Failed to fetch URL:"
  • "No valid thumbnail images were found"
  • "No images found on"

Font Test Utility

  • "Enhanced Font Detection Utility"
  • "Font Directory Information"
  • "Fonts Directory:"
  • "Directory Exists:"
  • "Directory Readable:"
  • "Font Mapping Status"
  • "Live Font Test"
  • "Generate Test Image"

User Instructions

  • "How to Use the Cropper"
  • "Click and drag the green box to position your crop"
  • "Drag corners or edges to resize"
  • "Click a thumbnail below to switch images"
  • "Use overlays for star ratings and text"
  • "Click Capture to save or Capture and NEXT to continue"

Keyboard Shortcuts

  • "Arrow Keys - Move selection"
  • "+/- - Resize"
  • "Enter - Submit"
  • "Esc - Cancel"

Version History

Version Date Changes
2.10 2025-12-15 Dual domain resolution when base href differs
2.00 2025-11-01 Real-time progress tracking, enhanced image detection
1.00 Initial Basic thumbnail scanning and cropping