|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-20 19:08 UTC] glavoie at mutehq dot net
Description: ------------ If I give the content of a MPEG file to imagecreatefromstring, it doesn't return an error. This is causing me an headach with HTTP graphic file upload since I must be sure that uploaded files are realli graphic ones for resizing. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
I use this script to convert images to JPEG with resizing when needed. When a MPEG file is given to imagecreatefromstring(), $source doesn't return false and I get an images($source) of 1 and a imagesy($source) of ~7000. When creating the new resized image with imagecreatetruecolor, the ratio is huge and an image of about 2.5 GB is created in memory. <?php if ( isset( $_GET['width'] ) ) $width = $_GET['width']; else $width = 0; $source = imagecreatefromstring( file_get_contents('1.mpg') ); if ($source) { if ( $width ) { $ratio = $width / imagesx( $source ); $resized = imagecreatetruecolor( $width, $ratio * imagesy( $source ) ); imagecopyresampled( $resized, $source, 0, 0, 0, 0, $width, $ratio * imagesy( $source ), imagesx( $source ), imagesy( $source ) ); $source = $resized; } ob_start(); imagejpeg($source); $photo = ob_get_contents(); ob_end_clean(); header( 'Content-type: image/jpeg' ); echo $photo; } ?>