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 7859879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:03:48+00:00 2026-06-02T22:03:48+00:00

Ok i’ve been at this for a while and need some help. I have

  • 0

Ok i’ve been at this for a while and need some help.
I have a directory of 3000+ images that i need thumbnails of, and i can’t quite get php to do it 🙁

I have never made thumbnails with php so this is new to me, I found a few scripts that create thumbnails as you upload images to the server, I will do this from here on out.

The image locations are stored as a URL in a mysql database.
I need it to create a thumbnail of the image and of course, update the database with the thumbnail url.

This is the script I’m using to integrate my needs into:
http://net.tutsplus.com/articles/news/how-to-dynamically-create-thumbnails/
I’m using the exact same functions.php & config.php files.

Here’s what I got:
$row[‘image’] is the location of each image ex: http://www.url.com/images/image.jpg
$filename I’m stripping the url so it just serves image.jpg

<?php
    require 'config.php';  
    require 'functions.php';  
    require 'db.php';  
    $sql = mysql_query("SELECT * FROM pics");  
    while($row = mysql_fetch_array($sql, MYSQL_ASSOC)){  

        $filename = preg_replace('['.$url.']', '', $row['image']);              
        $source = $row['image'];

        createThumbnail($filename);

        $thumb_loc = $url . "images/thumbs/" . $filename;
        $id = $row['id'];
        mysql_query("UPDATE pics SET image_thumb = '$thumb_loc' WHERE id = '$id'");
    }
?>

I’m serving a proper filename to $filename and image source to $source, so it should be working..
Here is the createThumbnail function in functions.php:

<?
function createThumbnail($filename) {

    require 'config.php';

    if(preg_match('/[.](jpg)$/', $filename)) {
        $im = imagecreatefromjpeg($path_to_image_directory . $filename);
    } else if (preg_match('/[.](gif)$/', $filename)) {
        $im = imagecreatefromgif($path_to_image_directory . $filename);
    } else if (preg_match('/[.](png)$/', $filename)) {
        $im = imagecreatefrompng($path_to_image_directory . $filename);
    }

    $ox = imagesx($im);
    $oy = imagesy($im);

    $nx = $final_width_of_image;
    $ny = $final_height_of_image;

    $nm = imagecreatetruecolor($nx, $ny);

    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

    if(!file_exists($path_to_thumbs_directory)) {
      if(!mkdir($path_to_thumbs_directory)) {
           die("There was a problem. Please try again!");
      }
       }

    imagejpeg($nm, $path_to_thumbs_directory . $filename);
    $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
    $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a    thumbnail has been created.';
    echo $tn;
}
?>

Here are the warnings:

Warning: imagecreatefromjpeg(images/fullsized/image.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in functions.php on line 7

Warning: imagesx(): supplied argument is not a valid Image resource in functions.php on line 14

Warning: imagesy(): supplied argument is not a valid Image resource in functions.php on line 15

Warning: Division by zero in functions.php on line 18

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in functions.php on line 20

Warning: imagecopyresized(): supplied argument is not a valid Image resource in functions.php on line 22

Warning: imagejpeg(): supplied argument is not a valid Image resource in functions.php on line 30

Can someone help me out here?

  • 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-02T22:03:50+00:00Added an answer on June 2, 2026 at 10:03 pm

    The problem appears to be that path you are specifying for the image file to manipulate is not valid from the location of the script.

    The file in the example is images/fullsized/image.jpg and the relevant error is failed to open stream: No such file or directory in functions.php on line 7

    You will need to use an absolute path when telling imagecreatefromjpeg what file to open e.g. $_SERVER['DOCUMENT_ROOT'] . '/images/fullsized/image.jpg' or /home/yoursite/public_html/images/fullsized/image.jpg.

    A full path or absolute path is a path that points to the same
    location on one file system regardless of the working directory or
    combined paths. It is usually written in reference to a root
    directory.

    All of the other error messages are just side effects of the image failing to open. Because the path was incorrect, no GD image was created and therefore the functions being called on it will not work.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.