# A small imagecopyresampled issue

**URL:** https://forum.kirupa.com/t/a-small-imagecopyresampled-issue/197558
**Category:** programming
**Created:** [August 17, 2006, 12:39pm UTC](https://forum.kirupa.com/t/a-small-imagecopyresampled-issue/197558 "2006-08-17T12:39:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tanel96](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@tanel96](https://forum.kirupa.com/u/tanel96)
#### Post date: [August 17, 2006, 12:39pm UTC](https://forum.kirupa.com/t/a-small-imagecopyresampled-issue/197558/1 "2006-08-17T12:39:04Z")

</div>

by using the following script i get this error message:

```auto

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10432 bytes) 

```

```php

function createthumb($name,$filename)
{
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
 
$thumb_w=150;
$thumb_h=150;
 
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename); 
} else {
imagejpeg($dst_img,$filename); 
}
imagedestroy($dst_img); 
imagedestroy($src_img); 
}

```

It happens when the images are bigger than 3Mpixels
