Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:36:12+00:00 2026-06-13T17:36:12+00:00

Really racking my brain, I’ve been looking into this for 2+ days. Goal? Click/select

  • 0

Really racking my brain, I’ve been looking into this for 2+ days.

Goal? Click/select a subdirectory with images; on Submit, a batch process will run using GD on the whole DIR chosen, creating thumbs in a /thumbs folder on the same server.

Status? I can do this for a single file at a time, need to do multiple files at once.

Here’s my functioning one-off code:

$filename = "images/r13.jpg";

list($width,$height) = getimagesize($filename);

$width_ratio = 166 / $width;
if ($height * $width_ratio <= 103)
{
    $adjusted_width = 166;
    $adjusted_height = $height * $width_ratio;
}
else
{
    $height_ratio = 103 / $height;
    $adjusted_width = $width * $height_ratio;
    $adjusted_height = 103;
}

$image_p = imagecreatetruecolor(166,103);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p,$image,ceil((166 - $adjusted_width) / 2),ceil((103 - $adjusted_height) / 2),0,0,ceil($adjusted_width),ceil($adjusted_height),$width,$height);

imagejpeg($image_p,"images/thumbs/r13.jpg",70);

As you can see, the script is targetting a single file, I would like to iterate through a directory instead of specifying a name.

(I will also look into imagemagick, but at the moment it is not an option.)

I’ll keep going through SO etc, but any help would be tremendous.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:36:14+00:00Added an answer on June 13, 2026 at 5:36 pm

    you need to make a function from this code:

    function processImage($filename){
        list($width,$height) = getimagesize($filename);
    
        $width_ratio = 166 / $width;
        if ($height * $width_ratio <= 103)
        {
            $adjusted_width = 166;
            $adjusted_height = $height * $width_ratio;
        }
        else
        {
            $height_ratio = 103 / $height;
            $adjusted_width = $width * $height_ratio;
            $adjusted_height = 103;
        }
    
        $image_p = imagecreatetruecolor(166,103);
        $image = imagecreatefromjpeg($filename);
        imagecopyresampled($image_p,$image,ceil((166 - $adjusted_width) / 2),ceil((103 - $adjusted_height) / 2),0,0,ceil($adjusted_width),ceil($adjusted_height),$width,$height);
    
        imagejpeg($image_p,"images/thumbs/".basename($filename),70);
        imagedestroy($image_p);
    }
    

    Please note last two lines of this function: it writes thumb basing on passed fiulename and destroys resource, to free memory.

    Now apply this to all files in directory:

    foreach(glob('images/*.jpg') AS $filename){
        processImage($filename);
    }
    

    and basically that’s it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is really racking my brain, but maybe I'm trying to hard. I'm passing
Alright, I've been racking my brain, reading up excel programming for dummies, and looking
I really don't know what's going on here, I've been racking my brain for
I have been racking my small brain for ages now, so can this be
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
I've been racking my brain trying to get my softphone to dial numbers on
I've been raking my brain trying to figure this one out. I have a
Really simple problem: I want to split a connection string into its keyword /
Really ripping my hair out on this one. I have a JAAS Authentication Provider
Really wish i was God, then I would understand what this means: The element

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.