Results 1 to 7 of 7

Thread: Batch image processing

  1. #1
    Join Date
    Jul 2007

    Batch image processing

    I need to create an automated process that generates the thumbnails of all the images contained in a directory (those that have no thumbnail yet). The problem is the size of these images, and their number is quite considerable. These images have between 1-5 MB.

    I said my coworkers the easiest way for this would be to batch process the images with Photoshop, but they said they prefer something which is not subjected to use Photoshop everytime a new image is added to the directory.

    I tried another way, which wasn't smart: Collecting the info of the files in an array, then looping thorugh it to make AJAX calls in order to process each one in the background. However, as you might guess, this caused the browser to freeze, and not all the images were processed, due to a timeout, I guess. I must say that I used the GD library and as far as I know, ImageMagick is quite faster.

    My question is: is there an efficient way to do this with PHP+javascript asynchronously? Something like queueing the images. And much better, with some sort of notifier for each processed image.
    I also saw once another batch processing with page refresh for each image. This could be interesting too by default.

    If you know some good tutorial for this it would be enough.
    Last edited by Jazztronik; 05-11-2012 at 04:30 PM.

  2. #2
    Join Date
    Aug 2004
    I don't think that AJAX calls would be a problem in and of themself, but if you call a PHP script via AJAX and, say, the PHP script crashes -- such as due to memory issues due to a large number of pixels in an image -- it would never send a HTTP response, so the JavaScript on the browser would just keep waiting for a response.

    If the IMagic extension is available to you, I believe it's less of a memory problem (whatever memory it uses is not charged against PHP's max memory setting). Otherwise, you can use getimagesize() to find the width and height of an image, multiply them and then multiply that product times 4 (32bits/pixel) to get an idea how much memory will be needed. At that point you can either go ahead and process the image if you think you have enough memory, or reject it (and send an error response so you know you have to handle it manually), or perhaps alter your memory limit accordingly (e.g. via ini_set()).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    May 2012
    hey buddy,

    you should have created a thumbnail size image before you uploaded the image (in case your image if from a form).

    use simpleImage class to resize your image.
    source: http://www.white-hat-web-design.co.u...ages-with-php/

    to create thumbnail size for your image in you directory,

    fetch your files then loop the resizing code per image.

    you can use opendir() function to do this.


    while(*condition fetching data form directory*){

    //do the resizing here


  4. #4
    Join Date
    Jul 2007
    Hello jr and NogDog,

    jr.wramirez: Thanks for the tip about the SimpleImage class. Looks pretty handy. Anyway, that's not what is causing me problems. I'm using CodeIgniter and it comes with a nice image manipulation class. There is no need to upload anything in this case: the big images are dumped with an FTP client (Filezilla). They must be there in order to allow the users to download them.

    NogDog: one question that still confuses me: does PHP do multitask? I mean when Javascript (JQuery in particular) loops though the array containing the files info and makes the AJAX calls, those calls are supposed to be made in a very short time.

    Does PHP queue all these requests so as to process one by one, or start processsing them until it runs out of memory? Or in other words, does PHP process a given number of requests at the same time?

  5. #5
    Join Date
    Aug 2004
    If you send several separate AJAX requests, as far as the web server is concerned, those are all separate HTTP requests that are completely unrelated to each other, so each fires off a separate invocation of your PHP script. Those requests would not effect each other as far as the PHP max memory limit, as that is on a per-request basis -- but it could impact total server memory if they are all running at once on the server, I suppose. (I'm not enough of a server/sysadmin sort to know if this would be a real problem or not.)

    I would be inclined to send the AJAX requests sequentially rather than concurrently: send request 1, wait for the response from the server (whether success or failure), and have the AJAX callback function then trigger the next AJAX request in the queue, etc... At the very least, such an approach might make it easier to debug where the actual problem is, rather than trying to figure out which request out of n concurrent requests is the culprit.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  6. #6
    Join Date
    May 2012
    Most elegant way to do this is to loop dir and use PHP GD library (http://php.net/manual/en/book.image.php)

  7. #7
    Join Date
    Jul 2007
    Thanks NogDog! you've been very helpful. I'll do it that way.

    signorm68: thanks for trying to help but please read the thread first (at least the 1st post). Seems that you've only read the title.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09638 seconds
  • Memory Usage 2,905KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates