473,695 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to make a thumbnail but fails

pek
I created a file name image.php which contains only the following code:

<?php
function createThumbnail ($picture,$thum b,$new_w,$new_h ) {
$extension=subs tr($picture,str rpos($picture," .")+1);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
$src_img=imagec reatefromjpeg($ picture);
break;
case "png":
$src_img=imagec reatefrompng($p icture);
break;
case "gif":
$src_img=imagec reatefromgif($p icture);
break;
case "bmp":
$src_img=imagec reatefromwbmp($ picture);
break;
}

$old_x=imagesx( $src_img);
$old_y=imagesy( $src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w ;
$thumb_h=$old_y *($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x *($new_w/$old_y);
$thumb_h=$new_h ;
}else{
$thumb_w=$new_w ;
$thumb_h=$new_h ;
}

$dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_ img,$thumb);
break;
case "png":
imagepng($dst_i mg,$thumb);
break;
case "gif":
imagegif($dst_i mg,$thumb);
break;
case "bmp":
imagewbmp($dst_ img,$thumb);
break;
}

imagedestroy($d st_img);
imagedestroy($s rc_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Locatio n:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.

Jun 27 '06 #1
4 1437

pek wrote:
I created a file name image.php which contains only the following code:

<?php
function createThumbnail ($picture,$thum b,$new_w,$new_h ) {
$extension=subs tr($picture,str rpos($picture," .")+1);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
$src_img=imagec reatefromjpeg($ picture);
break;
case "png":
$src_img=imagec reatefrompng($p icture);
break;
case "gif":
$src_img=imagec reatefromgif($p icture);
break;
case "bmp":
$src_img=imagec reatefromwbmp($ picture);
break;
}

$old_x=imagesx( $src_img);
$old_y=imagesy( $src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w ;
$thumb_h=$old_y *($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x *($new_w/$old_y);
$thumb_h=$new_h ;
}else{
$thumb_w=$new_w ;
$thumb_h=$new_h ;
}

$dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_ img,$thumb);
break;
case "png":
imagepng($dst_i mg,$thumb);
break;
case "gif":
imagegif($dst_i mg,$thumb);
break;
case "bmp":
imagewbmp($dst_ img,$thumb);
break;
}

imagedestroy($d st_img);
imagedestroy($s rc_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Locatio n:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.


If you actually want to display the image, you should call it as if it
were a real one:
<img src="image.php? vars" > in the html, not include it in another PHP
file.

Anyway, does the error give you a line or something? It appears because
text/whitespace is already outputted before the image is ...

Frizzle.

Jun 27 '06 #2
pek
I don't want to output the thumbnail. I simply want to create a
thumbnail with this function. I call this function from a page where I
upload a photo, create a thumbnail out of it, save some changes to the
database, and then redirect to the homepage. If I want to see the
uploaded image I simply find it under "photos/uploadedimg.jpg " and
"photos/thumbnails/uploadedimg.jpg " (the second is created with this
function).

frizzle wrote:
pek wrote:
I created a file name image.php which contains only the following code:

<?php
function createThumbnail ($picture,$thum b,$new_w,$new_h ) {
$extension=subs tr($picture,str rpos($picture," .")+1);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
$src_img=imagec reatefromjpeg($ picture);
break;
case "png":
$src_img=imagec reatefrompng($p icture);
break;
case "gif":
$src_img=imagec reatefromgif($p icture);
break;
case "bmp":
$src_img=imagec reatefromwbmp($ picture);
break;
}

$old_x=imagesx( $src_img);
$old_y=imagesy( $src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w ;
$thumb_h=$old_y *($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x *($new_w/$old_y);
$thumb_h=$new_h ;
}else{
$thumb_w=$new_w ;
$thumb_h=$new_h ;
}

$dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_ img,$thumb);
break;
case "png":
imagepng($dst_i mg,$thumb);
break;
case "gif":
imagegif($dst_i mg,$thumb);
break;
case "bmp":
imagewbmp($dst_ img,$thumb);
break;
}

imagedestroy($d st_img);
imagedestroy($s rc_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Locatio n:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.


If you actually want to display the image, you should call it as if it
were a real one:
<img src="image.php? vars" > in the html, not include it in another PHP
file.

Anyway, does the error give you a line or something? It appears because
text/whitespace is already outputted before the image is ...

Frizzle.


Jun 27 '06 #3
pek wrote:
I created a file name image.php which contains only the following code:

<?php
function createThumbnail ($picture,$thum b,$new_w,$new_h ) {
$extension=subs tr($picture,str rpos($picture," .")+1);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
$src_img=imagec reatefromjpeg($ picture);
break;
case "png":
$src_img=imagec reatefrompng($p icture);
break;
case "gif":
$src_img=imagec reatefromgif($p icture);
break;
case "bmp":
$src_img=imagec reatefromwbmp($ picture);
break;
}

$old_x=imagesx( $src_img);
$old_y=imagesy( $src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w ;
$thumb_h=$old_y *($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x *($new_w/$old_y);
$thumb_h=$new_h ;
}else{
$thumb_w=$new_w ;
$thumb_h=$new_h ;
}

$dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_ img,$thumb);
break;
case "png":
imagepng($dst_i mg,$thumb);
break;
case "gif":
imagegif($dst_i mg,$thumb);
break;
case "bmp":
imagewbmp($dst_ img,$thumb);
break;
}

imagedestroy($d st_img);
imagedestroy($s rc_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Locatio n:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.


Make sure you don't have *any* extra characters outside of the <?php and ?>
tags. That includes whitespace such as blank characters and newlines.

A common cause, for instance, is a blank or a newline character after the ?>.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 27 '06 #4
pek
Can somebody copy paste the code to a image.php file and import it and
try creating a thumbnail to see what happens..?

createThumbnail (picture as String, thumb as String, new_w as Integer,
new_h as Integer)
Parameter: picture
Path to the image that will create a thumbnail out of it
i.e. C:\test.bmp
Parameter: thumb
Path to the folder which the thumbnail will be saved
i.e. C:\thumbs\
Parameter: new_w
New width of image
Parameter: new_h
New height of image

Jerry Stuckle wrote:
pek wrote:
I created a file name image.php which contains only the following code:

<?php
function createThumbnail ($picture,$thum b,$new_w,$new_h ) {
$extension=subs tr($picture,str rpos($picture," .")+1);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
$src_img=imagec reatefromjpeg($ picture);
break;
case "png":
$src_img=imagec reatefrompng($p icture);
break;
case "gif":
$src_img=imagec reatefromgif($p icture);
break;
case "bmp":
$src_img=imagec reatefromwbmp($ picture);
break;
}

$old_x=imagesx( $src_img);
$old_y=imagesy( $src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w ;
$thumb_h=$old_y *($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x *($new_w/$old_y);
$thumb_h=$new_h ;
}else{
$thumb_w=$new_w ;
$thumb_h=$new_h ;
}

$dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);
switch (strtolower($ex tension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_ img,$thumb);
break;
case "png":
imagepng($dst_i mg,$thumb);
break;
case "gif":
imagegif($dst_i mg,$thumb);
break;
case "bmp":
imagewbmp($dst_ img,$thumb);
break;
}

imagedestroy($d st_img);
imagedestroy($s rc_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Locatio n:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.


Make sure you don't have *any* extra characters outside of the <?php and ?>
tags. That includes whitespace such as blank characters and newlines.

A common cause, for instance, is a blank or a newline character after the ?>.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Jun 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3649
by: Phil Powell | last post by:
PHP 4.3.2 with --enable-exif I have the following class: <?php class ThumbGenerator extends MethodGeneratorForActionPerformer { function ThumbGenerator() { // CONSTRUCTOR
3
3678
by: Rennie deGraaf | last post by:
I'm working on this page (http://pages.cpsc.ucalgary.ca/~degraaf/test/test.html). In the central (green-bordered) area, I want a bunch of (red-bordered) blocks each containing a thumbnail image and some text. The blocks must be of fixed, equal size. (Obviously, I'll have to limit the amount of text to fit this size.) The text must be positioned below the image. Within the central area, I want these blocks to flow like text; ie, for...
6
1738
by: Trint Smith | last post by:
How can I show image thumbnail?? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
25
4058
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
9
3575
by: K P S | last post by:
Hi. I'm looking for a small script that will take a .zip archive and pull the first .jpg from the archive and convert it to a .png. The reason for this is I want to have tuhmbnails for these archives in nautilus under gnome. I would like something similar to the following code, which will pull a thumbnail from an openoffice.org (oasis) document. What I want is a little more involved, I guess, since I don't know the name of the file...
8
20361
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1: Start with original thumbnails & two empty sub directories STEP 2: Create smaller versions of the originals for one sub directory STEP 3: Create thumbnail version of the originals the other sub directory STEP 4: Create an index.html pointing to the...
11
2371
by: Jane | last post by:
Hi, I need some help (php rookie) to build a thumbnail page using php. I'v a mysql database containing links to the original image files. No thumbnails created so far. It would be nice when the thumbnail contains a link to the original file :-) Jane
2
1575
by: empiresolutions | last post by:
I've installed Imagemajick. phpinfo() shows it and GDlib 2.0 installed properly. I have tried multiple tests to get it to work and all have failed. Can someone please tell me what i am doing wrong. Below is my current test script. All images and php are in the same dir for testing. Thanks. <? exec("convert file.jpg -resize 100x75 new_file.jpg"); // display original photo if (file_exists('file.jpg')) { ?>
8
4691
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the moment I am using Ken Getz' code. at http://www.mvps.org/access/api/api0001.htm Thanks Arno R
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8977
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.