473,788 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I name an image when I create it?

So far I've got the code you see below. I've not yet figured out how
to change the name of the file. I'm creating several images of
different sizes. I need to give them all different names. How do I
control the name?

function makeImage($path ToImage=false, $desiredSize=fa lse) {
if (file_exists($p athToImage)) {
if ($desiredSize) {
// 04-26-03 - This whole next section is off limits till I find out
how to test for image support in the
// PHP build in use - my own hosting company doesn't offer support
for functions like imagecreatefrom jpeg.
//
// 05-25-03 - function_exists () is the correct way to test.
//
// 07-22-04 - when images are uploaded, a thumbnail should be
created.
//
// 11-16-04 - I'm going to try to revive this function today and
make it operational.
// It's been in the code but unused for a year and a half.
// Since most PHP installations don't have the GD library, I think
the way to go is
// to simply test for every function.

$controllerForA ll = & getController() ;
$resultsObject = & $controllerForA ll->getObject("McR esults",
"makeImage" );

if (function_exist s("getimagesize ")) {
if (function_exist s("imagecreate" )) {
if (function_exist s("imagecreatef romjpeg")) {
if (function_exist s("imagecopyres ized")) {
if (function_exist s("imagesx") && function_exists ("imagesy")) {
if (function_exist s("imagejpeg" )) {
if (function_exist s("imagecreatef romgif")) {
if (function_exist s("imagegif") ) {

$size = getimagesize($p athToImage);
// 04-13-03 - Now we make sure we only output the jpgs and
gifs
// 04-13-03 - this next line is to find out if we are
outputting jpg or gif
// WE ONLY OUTPUT JPG AND GIF
if ($size[2] == 1 || $size[2] == 2) {
$oldWidth = $size[0];
$oldHeight = $size[1];

// 11-20-04 - we reset the width to whatever the desired
size is.
// standardImageIn sert calls this function 4 times with
values of
// 50, 100, 250, and 400. We then compare the desired size
to the
// old width to get a ratioOfChange which we can then
apply to
// the height to get a propotional change. The division
will
// leave us with a float, but we need an integer for the
// height value, so we hit the result with round().
$newWidth = $desiredSize;
$ratioOfChange = $oldWidth / $desiredSize;
$newHeight = $oldHeight / $ratioOfChange;
$newHeight = round($newHeigh t);

$newImage = imagecreate($ne wWidth, $newHeight);

if ($size[2] == 2) {
$srcImage = imagecreatefrom jpeg($image);
imagecopyresize d($newImage, $srcImage, 0, 0, 0, 0,
$newWidth, $newHeight, imagesx($srcIma ge), imagesy($srcIma ge));
imagejpeg($newI mage);
} elseif ($size[2] == 1) {
$srcImage = imagecreatefrom gif($image);
imageCopyResize d($newImage, $srcImage, 0, 0, 0, 0,
$newWidth, $newHeight, imagesx($srcIma ge), imagesy($srcIma ge));
imagegif($newIm age);
}
}
}
}
}
}
}
}
}
}
} else {
$resultsObject->error("In makeImage, the second parameter should
have told us what width was desired for this image, but it did not.",
"makeImage" );
}
} else {
if ($pathToImage == "") {
$resultsObject->error("In makeImage(), the first parameter should
have told us where to find this image (what path to it), but it did
not.", "makeImage" );
} else {
$resultsObject->error("In makeImage(), we were told to resize an
image called '$pathToImage' but the image didn't seem to exist on the
server.", "makeImage" );
}
}
}
Jul 17 '05 #1
4 1725
lawrence wrote:
So far I've got the code you see below. I've not yet figured out how
to change the name of the file. I'm creating several images of
different sizes. I need to give them all different names. How do I
control the name?


The imagejpeg/gif/png ake an optional filename argument and output the
jpeg image to that file if it is given.
bool imagejpeg ( resource image [, string filename [, int quality]])
Your function can take the filename as an argument and store the image
to the fiven filename.
For example imagejpeg($imag e,$fname."-fmt-jpg".'jpg')

Other than that, you have far too many nested ifs .. cannot help but
think "d00d, you are screwed"

Jul 17 '05 #2
"lunatech" <r.*******@gmai l.com> wrote in message news:<11******* **************@ z14g2000cwz.goo glegroups.com>. ..
Other than that, you have far too many nested ifs .. cannot help but
think "d00d, you are screwed"


What's a better way to handle the situation? You and I both know that
90% of the people out there won't be able to use this code because the
PHP GD library won't be installed. What is your concern about this
code? That it will run slowly? I'm under the impression that
function_exists () is a fast function. It's not as if it needs to do
any complex calculations.

Still, if you know of a more concise way to guarantee that my fuction
will never call a PHP function that is not installed, I'd like to know
it.

One of the web design companies I work with has their servers with
Interland. The server setup is a nightmare. It's running Free BSD but
its a virtual environment such that its been hard for our local linux
gurus to upload a new RPM of PHP. For that reason they are still
running PHP 4.0.6 on their servers. For that reason, since they are
my biggest client, when I use functions in GD or PHP > 4.0.6 I tend to
test for the existence of the function.

It's a bad situation, but how else to deal with it? They are moving
all their clients to some new servers they've leased through
Rackspace, and Rackspace offers a much better setup. Till then, we
need to proceed carefully, writing PHP code that looks like Javascript
code, in the sense that we test excessively for the existence of
functions.
Jul 17 '05 #3
lawrence wrote:
"lunatech" <r.*******@gmai l.com> wrote in message news:<11******* **************@ z14g2000cwz.goo glegroups.com>. ..
Other than that, you have far too many nested ifs .. cannot help but think "d00d, you are screwed"


What's a better way to handle the situation? You and I both know that
90% of the people out there won't be able to use this code because

the PHP GD library won't be installed. What is your concern about this
code? That it will run slowly? I'm under the impression that
function_exists () is a fast function. It's not as if it needs to do
any complex calculations.
My concern is that the code is too complex. But that maybe just
because I have a small brain :-)

Still, if you know of a more concise way to guarantee that my fuction
will never call a PHP function that is not installed, I'd like to know it.
Yes, I think you can handle the above code more elegantly. From a
cursory glance it seems that

- All the functions (imagesx/y, imagecreatefrom jpeg, imagejpeg etc.)
*must* exist to make your function work correctly.

- you call a function *only* when it is guranteed to exist

- You do not have an else part i.e. if some function is not found, you
bail out.

My solution is as follows

function do_required_ima ge_functions_ex ist()
{
if (
function_exists (getimagesize) &&
function_exists (getimagecreate ) &&
function_exists (magecreatefrom gif) &&
function_exists (BLAH_BLAH)
)
return true;
else
return false;
}


function makeImage($path ToImage=false, $desiredSize=fa lse)
{
if (do_required_im age_functions_e xist())
{
YOUR CODE
}

else
{
HANDLE ERROR CONDITION
}
}


One of the web design companies I work with has their servers with
Interland. The server setup is a nightmare. It's running Free BSD but
its a virtual environment such that its been hard for our local linux
gurus to upload a new RPM of PHP.


In a vhost, you can compile and install your own version of PHP. Why
do you need RPMs for FreeBSD. maybe you should contact your hosting
provider for further guidance. From what I know, it can be done but
YMMV

Jul 17 '05 #4
lk******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
So far I've got the code you see below. I've not yet figured out how
to change the name of the file. I'm creating several images of
different sizes. I need to give them all different names. How do I
control the name?


1. Using md5() on parameters. eg. $image_name =
'img'.md5($x.$y .$size).'.jpg';
//imgacbd18db4cc2 f85cedef654fccc 4a4d8.jpg
2. http://in.php.net/uniqid

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

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

Similar topics

2
9353
by: Greg | last post by:
looking for an easy way for users to browse for a file on their local drive, and then have access automatically make a copy of that file (files will most likely be images) and save it under a new name (somehow relating it to the PK of the main table) in a directory on the server where the DB is stored... i realize that might not be the best wording of what im trying to do, so ill try explaining it a lil differently. each record created...
15
31813
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and help. Regards
12
6191
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses the DLL above. Now the application, together with the above DLL’s is successfully loading a TIF image file (62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200 DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08...
2
2287
by: Mango | last post by:
Hi there, I will be very happy if someone helps me. I need to create dynamic image, and save the state between the postback. I mean I've got 5 buttons and when I click on one of them, the image is creted with: System.Web.UI.WebControls.Image Img1 = new System.Web.UI.WebControls.Image(); Img1.ImageUrl = newPath; Panel1.Controls.Add(Img1);
15
5366
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
1
5799
by: Karl | last post by:
Can you create name tags with pictures using A2000? I have a table with an Employee name field and a field with a link to their gif picture. I was able to get a form to work using the Image Control and setting its Picture property to the gif link field in the on current event. In the Report (for the name tags) I added the Image control but I can't find a place to set the Picture property.
2
1761
by: Kevin Walzer | last post by:
I'm trying to avoid a *lot* of typing in my Tkinter application by associating image names with items in a list. Here is my sample list: self.catlist = I've also already created a bunch of images with names that correspond to the list above, i.e. self.all, self.installed, and so on. Here's the rest of my code: for item in self.catlist:
0
1526
by: u01jmg3 | last post by:
Hi, basically I create a png image on the fly and that all works fine but when I go to save the image it's taking the name of the .php script used to create it as its default name. e.g. I visit qrcode.php?id=100092 which creates a qrcode png image for "100092" which works fine. I then want to save this png image so I right click and pick "Save Picture As..." which displays a dialog that already has "File name:" filled in as "qrcode" which is...
10
1671
by: Keith G Hicks | last post by:
I'm hoping there's a simple way to do this. I need to show a dummy image in an asp image object if the file is missing. Here's my asp.net 2.0 markup: <asp:Image ID="imgGrad" runat="server" BorderColor="DimGray" BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl='<%# "~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>' ToolTip="Click to enlarge" /></td> "GradPhotoFileName" is stored in a field in a table. If the file...
0
9656
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
10366
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...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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
8993
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
7517
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
5399
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...
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.