hi,
i looking for a way to resize a picture of any any to a custum size.
in this moment i have pictures bigger than 3200px and i looking for a script
that can handle that, the last script that i have tested simple "explode"
with pictures bigger than 1800px
thanks a lot for your help
:)

Dani AI

Generated

Quick summary and practical fixes (ties to existing replies by , , and )

Large images usually fail when the PHP process runs out of memory or time. Server-side libraries (GD or Imagick), a thumbnailing package like phpThumb (mentioned by ), or client-side canvas resizing are common approaches. On shared hosts the main blockers are PHP memory_limit and max execution time; file dimensions (width * height) drive memory use, not just file size on disk.

Checklist and workflow to make resizing reliable

  • Check the image dimensions first with getimagesize() and reject/handle huge images before trying to allocate memory.
  • If you control PHP settings, bump memory_limit (temporarily with ini_set) based on an estimate: truecolor images need roughly width height 4 bytes plus overhead.
  • Use imagecreatetruecolor() + imagecopyresampled() (GD) rather than imagecopyresized() for quality.
  • Free memory with imagedestroy() as soon as possible.
  • For very large downscales, do progressive shrinking (downscale by halves repeatedly) to reduce peak memory.
  • If Imagick is available, prefer it for large files; it streams and is often far more memory-efficient.

Small, safe GD example (JPEG)

function resize_jpeg($src, $dst, $maxW, $maxH) {
  list($w,$h) = getimagesize($src);
  if ($w <= $maxW && $h <= $maxH) { return copy($src,$dst); }
  $ratio = max($w/$maxW, $h/$maxH);
  $nw = (int)($w/$ratio); $nh = (int)($h/$ratio);
  $srcImg = imagecreatefromjpeg($src);
  $tmp = imagecreatetruecolor($nw,$nh);
  imagecopyresampled($tmp,$srcImg,0,0,0,0,$nw,$nh,$w,$h);
  imagejpeg($tmp,$dst,90);
  imagedestroy($tmp); imagedestroy($srcImg);
  return true;
}

Extra notes
If you cannot increase memory on shared hosting, do client-side resizing with a JavaScript canvas before upload, use a background/cron job to process images, or call ImageMagick (convert) if available. If using phpThumb, verify and patch any deprecated functions for your PHP version as hinted. Also remember EXIF orientation for photos from phones; use exif_read_data() to correct rotation.

Recommended Answers

All 5 Replies

I use phpThumb. It requires a small change if you are using the latest PHP version, but I'm satisfied with it.

hi,
i use php 5 on a shared server, what is the "small change"?
thanks a lot for your help:)

the link given includes all the documentation, RTFM

You need to change the eregi (deprecated) in the code to preg_match. Only several lines are affected.

ya i use php thumb...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.