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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:27:41+00:00 2026-05-19T16:27:41+00:00

I have witten a function that copies some images onto a canvas and saves

  • 0

I have witten a function that copies some images onto a canvas and saves it to a file. My code is at the bottom of the post.

The code works fine when i try to copy 15 image onto the canvas, but when i try to copy 30 it just stops. No errors or exceptions…

I hope one of you can help me out 🙂

    $img        = imagecreatefromjpeg( $image );
    $imgWidth   = imagesx($img);
    $imgHeight  = imagesy($img);

    // CREATE CANVAS AND FILL WITH WHITE
    $canvas     = imagecreatetruecolor( $guidelines['canvasW'] * $dpi, $guidelines['canvasH'] * $dpi );
    $color      = imagecolorallocate( $canvas, 255, 255, 255 );
    imagefill( $canvas, 0, 0, $color );

    // COPY THE IMAGES ONTO THE CANVAS
    foreach( $guidelines['imageGuide'] as $guide ):

        $bestFit    = bestFit( $imgWidth, $imgHeight, $guide['W'] * $dpi, $guide['H'] * $dpi );
        if( $bestFit['rotate'] ) {
            $output = imagerotate($img, 90, 0);
        } else {
            $output = imagerotate($img, 0, 0);
        }
        imagecopyresampled($canvas, $output, $guide['X'] * $dpi, $guide['Y'] * $dpi, 0, 0, $bestFit['x'], $bestFit['y'], imagesx($output), imagesy($output));

        imagedestroy($output);
    endforeach;

$guidelines is an array. Here is an example which will copy 16 images onto the canvas

    $guidelines = array(    'canvasW' => 20,
            'canvasH' => 30,
            'imageGuide' => array(
                        array('W' => 18,    'H' => 13,  'X' => 1,   'Y' => 1.5),

                        array('W' => 3.5,   'H' => 4.5, 'X' => 1.25,    'Y' => 15),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 4.75,    'Y' => 15),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 8.25,    'Y' => 15),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 11.75,   'Y' => 15),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 15.25,   'Y' => 15),

                        array('W' => 3.5,   'H' => 4.5, 'X' => 1.25,    'Y' => 19.5),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 4.75,    'Y' => 19.5),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 8.25,    'Y' => 19.5),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 11.75,   'Y' => 19.5),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 15.25,   'Y' => 19.5),

                        array('W' => 3.5,   'H' => 4.5, 'X' => 1.25,    'Y' => 24),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 4.75,    'Y' => 24),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 8.25,    'Y' => 24),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 11.75,   'Y' => 24),
                        array('W' => 3.5,   'H' => 4.5, 'X' => 15.25,   'Y' => 24),
                    ),
                );
  • 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-05-19T16:27:42+00:00Added an answer on May 19, 2026 at 4:27 pm

    I’m going to guess that you are using too much RAM with this job. ImageCopyResampled has to write a lot to RAM with this job you have, and images can take up a lot of memory. Check memory_limit in your php.ini file, try increasing it and see if you can get through more/all of your images being written to the canvas. Good luck!

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

Sidebar

Related Questions

I have written code to perform a function that could take a while to
I have written a PHP function to take a video embed code that has
I currently have a function written called saveWorkout that saves an NSMutableArray to another
Hi there I have written a code that ietrates through whole array and copies
I have written function (actually a macro, but whatever) that works similarly to progn
I have written a jquery ajax function that I have added to js file
I have written the following code. I know that a higher order function is
I have written a function that gets a given number of random records from
I have written a function that positions a tooltip just above a textbox. The
I have written a javascript function that uses setInterval to manipulate a string every

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.