
SirXaph
Members-
Posts
11 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
SirXaph's Achievements

Newbie (1/5)
0
Reputation
-
create an image in one php file, load it in another php file.
SirXaph replied to SirXaph's topic in PHP Coding Help
Okay.. Sorry to post again but nobody's replied and I have more info that might help someone answer the question. I've found out that the best way to do what the test php files were doing is to use code like this: <?php ini_set('memory_limit', '80M'); ob_start(); include("test2.php"); $return_str = ob_get_contents(); ob_end_clean(); header('Content-Type: image/jpeg'); echo($return_str); ?> Problem with that though is that all I seem able to do with that code is load the image and echo it to the screen. I kinda wanted to be able to load it as a gd image and do stuff to it, which is why my tests all focus around loading the image using gd functions. There doesn't seem to be a way to load an image from a variable rather than from a filename. I'd rather not go down the route of saving a tempfile, then loading the image from there, unless that's the only way. Is there a way to do something similar to that code (which I grabbed from the php site) within an imagecreatefromjpeg() function? On an unrelated note, am I right in thinking it's not necessary to specifically set the header as jpeg when you're echoing the contents of a jpeg file (which should already include the header)? -
create an image in one php file, load it in another php file.
SirXaph replied to SirXaph's topic in PHP Coding Help
Okay forgive the double post but I've tested my issue further. Using the same example file from the last post, http://antarctica.go-forth.co.uk/test2.php is a jpeg file, loaded and displayed using gd. I've made a file called http://antarctica.go-forth.co.uk/test3.php which is identical, but instead of a .jpg image in the call to imagecreatefromjpeg() I actually put test2.php. <?php ini_set('memory_limit', '80M'); $im = imagecreatefromjpeg("test2.php"); header('Content-Type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?> So, it appears I can't load a jpeg created and returned by one php file into another php file that way. Does anyone know how I would go about doing this? -
create an image in one php file, load it in another php file.
SirXaph replied to SirXaph's topic in PHP Coding Help
No, I tried that already: http://antarctica.go-forth.co.uk/p2/test1.php They do change. Besides if I was hitting the php memory limit then the call to imagecreatefromjpeg() would fail and I would get an error I can check for, but the whole script shouldn't die and fail to continue after that point. two scripts - identical but for the size of the image. I use ini_set to set the memory limit to 80M first. http://antarctica.go-forth.co.uk/test.php http://antarctica.go-forth.co.uk/test2.php -
create an image in one php file, load it in another php file.
SirXaph replied to SirXaph's topic in PHP Coding Help
Would using mod_rewrite help? ie, making it so that requests for /thumbs/blah.jpg actually point to /resize.php?blah.jpg$t=1 ..? -
create an image in one php file, load it in another php file.
SirXaph replied to SirXaph's topic in PHP Coding Help
Using gd alone to resize the images unfortunately doesn't seem to be an option because my host seems to kill* any php script as soon as gd even loads an image that takes up more than about 10mb of ram and I intend to be working with several megapixel digital camera files 'as is'. Increasing the amount of memory allowed using ini_set doesn't have any impact either because the process itself seems to be terminated regardless of what memory_limit is set to. *and by kill I mean terminate, end process, etc, so there's not even any errors returned. I posted about that original issue here: http://www.phpfreaks.com/forums/index.php/topic,249061.0.html So.. is it possible to load a php file as an image from another php file? -
Hi, me again. I'm actually now creating a new image gallery from scratch using a mixture of ImageMagick and gd, and it's going quite well so far but I've hit a stumbling block with gd and just need to know if what I'm specifically trying to do is just impossible or if there's something else wrong. Right, the background - I have a php file called resize.php which works like this: check to see if resized image exists - if not, create it using ImageMagick ---then add the image headers directly, load and display the image using GD - if so, just add the already pre-existing image directly. The reason I coded it that way was to prevent one of the issues with the other gallery, which was that the thumbnail and web-resized images would effectively have a different filename depending on whether the resized image had already been created (/resized/###.jpg) or whether it needed to be created at display time (resizeimg.php?img=###.jpg). So, the way it works is that resize.php?img=subdir/filename.jpg is the url I always use to get the image, and resize.php?img=subdir/filename.jpg&t=1 gets that image's thumbnail. examples: http://antarctica.go-forth.co.uk/p2/resize.php?img=10b/DSCF3337.jpg http://antarctica.go-forth.co.uk/p2/resize.php?img=dscf1116.jpg&t=1 What I'm trying to do now is to obtain these images using a call to imagecreatefromjpeg() in another file: $src = "resize.php?img=$srcdir_s$image&t=1"; //echo $src; $img=imagecreatefromjpeg($src); header('Content-type: image/jpeg'); header('Content-transfer-encoding: binary'); imagejpeg($img, null, $resizequal); imagedestroy($img); exit(); However this code isn't doing anything. For test purposes I put that echo $src; in there. uncommented, the script will display the image source name for example resize.php?img=dscf1116.jpg&t=1 - and if I just type in the address bar (after the script's path) loads the image fine - you wind up with the same url I used above.. so it IS a jpeg image. Is it something to do with the fact that while the headers and content of that request will return a jpeg image, the file itself is a php script? The php manual doesn't say that I can't do this but then it doesn't say I can either.. I can code around this, just I'd rather not have to because I'd need to duplicate a lot of what resize.php can do in another file, and that just feels messy.
-
Yeah I was thinking maybe that. Problem there really is that it likely means that my code isn't as portable or transferable as I'd like it to be but I guess such is life. Oh, and you were faster at posting than I was at editing, not sure if my edits above make any difference or help at all though, I just figured I'd add the basic code I'm using.
-
Thanks Neil I am now having more success with resizing the images using an imagemagick exec() call - for example: http://antarctica.go-forth.co.uk/photos/sp_resize.php?source=./2009-03-14_In_Transit/DSCF0686.jpg However, occasionally the exec calls seem to crash (or at least, not work), resulting in no image being created (which in my code causes an error icon to be loaded instead when the time comes to load and display the resized image); Sometimes though it seems the whole resize script crashes resulting in no image being returned at all.. it doesn't happen all the time or with the same images when it does; a simple refresh fixes it. I guess that would be my host again doing funky stuff and killing processes that would've used too much memory were we still in 1998... the fact that I can notice it on my site when it's just me browsing it is a bit worrying, considering I'm the only person with the url right now. I can foresee it being terrible if traffic was higher. Any thoughts as to how I can minimise these issues? The code already tries to limit the number of times the resizes are done (because obviously it shouldn't be doing the exec again for a certain image after the resized version has been saved).. I'm not totally familiar with exec() style functions and am wondering if there's a better way of doing it than this: $command = "convert " . $src . " -resize " . $maxwidth . "x" . $maxheight . " " . $dest; exec($command, $out, $rcode);
-
Thanks That was the conclusion I came to as well. Seems like a really odd way of doing things though; why not just set the maximum memory usage in php.ini and prevent me from overriding - at least that'd give me a usable error message. I've sent a message to my host politely explaining that it's 2009 now, the amount of ram even an 8 megapixel image takes up should be pretty negligible these days provided it's not happening all the time (which it isn't, that's why I'm caching the resized images); I'll see what they say. If anyone knows of a workaround allowing an image to be resized without loading the whole thing into memory first or something similar then please let me know. It's disappointing to have to shrink my images down in order to put them into a gallery.
-
Hi! I'm new. I have searched though, I think this is my host being strange but I figured I'd post here in case there was any kind of workaround. I'm trying to retrofit a simple php image gallery & trying to iron out the bugs, yet the most irritating bug I can find seems to actually be to do with server settings or something like that. The code in question checks to see if a cached thumbnail and resized version of the image exist, then if they don't calls a resize function which loads the image, resizes it, and saves the cached thumbnails for future use. The problem occurs when the images get over 2000 pixels x 1500 (exactly - 1999 x 1499 is fine). Now, from what I understand if there's an error then I should expect either an error, or at the very least the function should return false like the php manual says it should. Unfortunately the function doesn't seem to actually return anything at all - the whole php script crashes at this point with a 500 server error. I have to comment out or make the imagecreatefromjpeg call point to a smaller image to get the remainder of the code to run. Just to check the server error wasn't caused by anything else I made this code snippet: <?php $im = imagecreatefromjpeg("dscf3717.jpg"); header('Content-Type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?> And I made an exact duplicate with a smaller image file. Those php files are here: http://antarctica.go-forth.co.uk/photos/test.php http://antarctica.go-forth.co.uk/photos/test1.php and the images are here: http://antarctica.go-forth.co.uk/error.jpg http://antarctica.go-forth.co.uk/photos/dscf3717.jpg Just so you know: I don't get any memory errors - I get no errors at all - though the memory limit for my server is apparently at 40M which should be enough (2000 pixels x 1500 should be a memory footprint of about 17M according to the formula people worked out in the comments on the php manual). The part of the resize code that's causing issues: switch(strtolower($path["extension"])){ case "jpeg": case "jpg": $original=imagecreatefromjpeg($source); break; case "gif": $original=imagecreatefromgif($source); break; case "png": $original=imagecreatefrompng($source); break; default: break; } if (!$original) { $original=imagecreatefromjpeg("../error.jpg"); header('Content-type: image/jpeg'); header('Content-transfer-encoding: binary'); imagejpeg($original, null, $resizequality); exit(); } as you can see I'm checking for a false return from imagecreatefromjpeg, and substituting the error image when that happens, however because the code seems to just stop, rather than returning an error this part of the code isn't executed. Suggestions?