Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Font Color In Jpeg Image (nearly) Always Orange


I am trying to run a basic script that displays an existing jpeg image
and writes some text over it. Sounds simple, but I cannot seem to be
able to colour the font correctly. In the example below it should be
black but it comes out orange. In fact, even if I change the colour to
0, 0, 255 it's orange.

I've read in the PHP documentation (the user contributed notes) that
there are issues with jpeg font colouring. But I've not seen any
details. Can anyone shed light on this for me please?

The example code below is called as a function. The $image variable is
a path to the existing image file and the $ttf variable is a path to a
TrueType font. The $text variable contains a text string.

header("Content-type: image/jpeg");
$base_image = imagecreatefromjpeg($image);
$font = $ttf;
$fontcolor = imagecolorallocate($base_image, 0, 0, 0);
imagettftext($base_image, 18, 0, 10, 100, $fontcolor, $font, $text);
imagejpeg($base_image); imagedestroy($base_image);




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Color Or Font Size In The Sprintf() Function?
If so can some please show me an example? I would like to use CSS but will use the <font> tag if mandatory.

Imagejpeg Generating String Not Image Even With Header("Content-type:image/jpeg")
does anyone know why i can't generate images with:
header("Content-type:image/jpeg");
imagejpeg($img_number);

i've tried different examples but i always get a text output as if the
header doesn't make a difference at all.

<?php
//random_number.php
$img_number = imagecreate(100,50);
$white = imagecolorallocate($img_number,255,255,255);
$black = imagecolorallocate($img_number,0,0,0);
$grey_shade = imagecolorallocate($img_number,204,204,204);

imagefill($img_number,0,0,$grey_shade);
ImageRectangle($img_number,5,5,94,44,$black);
ImageRectangle($img_number,0,0,99,49,$black);

header("Content-type:image/jpeg");
imagejpeg($img_number);
?>

Jpeg Image Decompiling
I have found a couple of sites that allow a visitor to upload an image
and the site returns either the "average color", or a palette of colors.
Several of them use PHP to accomplish this. I have requested the source
code, but have not gotten a response (even though one site states
"source code available on request"). It is obvious that they read the
colors of each pixel and them manipulate that data. I would like to be
able to do something similar.

I'm not very familiar with the PHP image functions, but have been able
to figure out how to read pixel color on indexed color images, but not
on jpegs. The best I can do now is convert a jpeg to a 256 indexed
color image, and then read pixel color. Unfortunately too much of the
original data gets lost.

Does anyone know how to determine the color of jpeg pixels, or can you
point me to a good tutorial on PHP image functions.

For what it's worth, one of the things I want to do is determine the
distribution of each color (i.e. 345 pixels of rgb1, 2436 pixels of
rgb2, etc.), and possibly manipulate the image by removing and/or
replacing any given color.

Image Jpeg Function
I am having some problems using the imagejpeg() function. The script i am wrote successfully saved a resized image, but displays a white page with the url that loads without the inclusion of the imagejped code. 

(instead of resizing the image and loading the page mysite.com, it resizes the image and displays a white page with the url mysite.com written in the upper left hand corner) Is this function trying to create its own new page, and how can i get it to load the page instead of displaying the url, as the php file does without the inclusion of the imagejpeg code? Code:

GD & JPEG: Dynamic Image Support
I've got the GD and JPEG Libraries installed on my Linux box (running apache 1.3.9), and have tried to configure PHP "--with-gd" and "--with-jpeg" pointing to the correct locations of each library - with no luck.

How I Can Extract A Text From Image(jpeg, Tiff,etc..) ?
How I can extract a text from image : jpeg, tiff, bmp, etc.. using PHP
is possible ? What class i must use ?

Image With Functions And Font Face.
does anybody know how to change font-face in Arial,Verdana etc. when i'm
using image-functions of PHP?

Font-Size is clear to me...
$fontSize=2
imagestring($im, $fontSize, $px, 34+($i*1.2), $line, $orange);

Image(jpeg) Upload & Resize Loses Colour?
I am uploading an image to a server and resizing the image then saving it to a directory,I had it working fine on my local machine (windows) but when i uploaded the code to the server (linux) - same directory structure etc, it didnt work the colour appeared to be removed from the image, as though the number of colours in the image was reduced to 2 or 4 or something?

has anybody come accross similar problems with GD or image functions in php?

Checking If Jpeg Image Exists On Remote Server
I need to check if a jpeg file exists on a remote server. How would I do that? I have tried the url_exists functions in PHP manual but with no luck...

Changing Font Size Of GDF Fonts Over PNG Image
I used imagecreatefrompng("ur.png"), and created a png image. And used
imagestring($im, $fontgdf, $leftPos, $height, $text, $txtcolor); to write over the png image. I downloaded and used gdf fonts. Function imagestring() does not take fontsize as parameter, therefore i could not change the font size.

Select Image By Color
can any of u guys point me in the direction of a "select all images with
this color" script?

Like what they use @ istockphoto.com, where u get a pallette of colors
and click the desired color, after wich a selection of images with the
clicked color as dominant shows up.

Replace Color In Image With GD
I've been looking at php.net and here in the forums, but I cannot find the right function to replace a color in a image with GD. ie: I want to change the black color for white. Wich function should I use? I've been using imagecolortransparent() to transform the BLACK color to "transparent" but, I think is better to replace it to white.

GD And Changing The Color Of An Image
I'm trying to come up with a script that will change the color of a transparent png to a new color. Like #FF0000 to #0000FF. The images I'm using are solid color with a transparent background. Anyways it's not going so well. I have this script that works for palpated images but when I try to use it with an image that has alpha transparency it gets all weird on me and shows up as solid blocks of color. Code:

Apply Color To B/w Image
I have a grayscale image, (just three colors) and I want to use php to apply color to it, so it turns, say, blue. I have a ton of these greyscale images and a lot of colors, so I want to use php to do it when needed instead of doing them all by hand in photoshop. I have done some searching but I'm not even sure what to call this.

Replace One Color With Another In An Image?
I have the following script that replaces all red pixels on an image with a specified image tile, but I want to be able to swap the red with another hex color which I'll feed to the script. Could somebody show me how to do this? Code:

Create Image For Each Individual Character In A Truetype Font (.ttf)
Is there any possible way to create an individual image for each character in a TrueType font file (.ttf)? Eiether in PHP, or some Windows program that would do it?

Bg Color Uploading Transaprent Image
I just have a simple upload and resize image for thumbnail code...and it works okay..my problem is.. if I'm uploading a transparent *.gif image it will create a black bg color for thumnail image..and for the original image as well..so is there any solution to this.I mean I want the image and the thumbnail still remain transparent when the uploading process done...not fill in the bg with black color..like what I have just now . PHP Code:

Image Create Default Background Color
I have a script that crops and image and resizes it, but that's not the problem.

If the image is smaller than the crop area, PHP just fills it in with black.

Is there a way to make PHP fill it in with white instead of black?

Paint An Opaque Layer Of Color Over An Entire Image?
Is there code (if so, what is it?) to paint an opaque layer of color over an entire image?

Read True Type Font (ttf) Tags (font Name...)
I try to acces to the font name of my ttf fonts using a php script
with the file name.
I've found a script reading idv tags from mp3 files, but it's too
specific.
Can anyone say me how to read a ttf file in php ?

[GD] Could Not Find/open Font - Font Problem
I know this subject was up several times but Icant get it work
use gd2 on win32
<?
putenv('GDFONTPATH=f:swdfont');
$font = "f:/swd/font/arial.ttf";
$im = imagecreate (250, 28);
$black = ImageColorAllocate ($im, 0, 0, 0);
$yellow = ImageColorAllocate ($im, 235, 235, 51);
ImageTTFText ($im, 20, 0, 10, 20, $yellow, $font,
"comming text or not?");
ImagePNG($im,test.png);
?>
<img src="test.png" alt="image">

but I allway get error about not finding font ..

Color Background Cell Color Per Row
I am trying to create a display page for my database records, where each display-row has a different color than the previous one. I think I can do that if I where able to get the rownumber of the recordset. Than for each 'even' number I asign a color, and for each 'uneven' number a different one. Code:

Still Not Compiling Jpeg With Gd
I am building on Linux Redhat 7.1

First I build GD with information about zlib/jpeg/png/freetype directories

thanks to some advise on another post, I tested the build

nm libgd.a | grep gdImageCreateFromJpeg
0000040c T gdImageCreateFromJpeg
00000438 T gdImageCreateFromJpegCtx

nm libgd.a | grep gdImageCreateFromPng

U gdImageCreateFromPngCtx
00000030 T gdImageCreateFromPngSource
000000cc T gdImageCreateFromPng
000000f8 T gdImageCreateFromPngCtx

OK - I think that GD is functioning with the above.

So now build php

------------------------------------------
./configure --with-mysql=/usr/local/mysql
--with-pgsql=/usr/local/pgsql
--with-apache=../apache_1.3.23
--with-pdflib=/usr/local/pdflib
--with-zlib=/usr
--with-gd=/usr
--enable-gd-native-ttf
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-freetype-dir=/usr
--with-ttf
--with-xml
--enable-ftp
--with-openssl
--with-pear

-------------------------------------------

This is where I identify the problem

etc ....

-------------------------------------------

checking whether to include GD support... yes
checking whether to enable truetype string function in gd... yes
checking for the location of libjpeg... yes
checking for jpeg_read_header in -ljpeg... (cached) yes
checking for the location of libpng... yes
checking for png_info_init in -lpng... (cached) yes
checking for the location of libXpm... no
If configure fails try --with-xpm-dir=<DIR>
checking for freetype(2)... yes
checking whether to include include FreeType 1.x support... yes
no - FreeType 2.x is to be used instead
checking whether to include T1lib support... no
checking for gdImageString16 in -lgd... (cached) yes
checking for gdImagePaletteCopy in -lgd... (cached) yes
checking for gdImageCreateFromPng in -lgd... (cached) no
checking for gdImageCreateFromGif in -lgd... (cached) no
checking for gdImageGif in -lgd... (cached) no
checking for gdImageWBMP in -lgd... (cached) yes
checking for gdImageCreateFromJpeg in -lgd... (cached) no
checking for gdImageCreateFromXpm in -lgd... (cached) yes
checking for gdImageCreateFromGd2 in -lgd... (cached) yes
checking for gdImageCreateTrueColor in -lgd... (cached) no

-----------------------------------------

so for those who have not skimmed over the above, you can see that while the headers were identified, the functions gdImageCreateFromJpeg and
gdImageCreateFromPng were not found in the gd library, even though they are there and were found manually previously.

Not Display Gif/jpeg
I have a problem with "Blobbing data with PHP and MySQL" by Mitchell Harper on Weberdev or any other tutorial like this for upload images on a blob field, then download and display them on a web page. A very(!) simple problem but every other message on this forum or on others forums haven't solved yet.
The script works well for .txt files, but not for gif or jpeg files. If I don't specify "Content-type: image/gif(or jpeg)" it sends me (as I expected) the binary code of the file, but with the proper Content-type, it displays "The image 'downloadfile.php ' cannot be displayed, because it contains errors".
Naturally I tried with different jpegs or gifs.
If it can be useful, output of "upload.php" is:
"The details of the uploaded file are shown below:

File name: picture.jpg
File type: image/jpeg
File size: 15590
Uploaded to: C:WINNTTEMPphp6.tmp"
So (I think) the upload operation works fine.

I'using PHP4.0.6 and MySQL3.23.43 on Windows2000.

GD Support For Both GIF And JPEG
I want to know it it's possible to have both GIF and JPEG support in one PHP installation. Right now I want JPEG support for an online photo gallery program I'm working on (I've currently got the GD library between v.1.3 and v.1.6.1 which has GIF support but not JPEG support), but I'm afraid that if I install a newer version of GD (which doesn't have support for GIF due to the Unisys patent problem) and I want GIF support later on,

I won't be able to have GIF support, or get it again, because the old GD ibrary with GIF support isn't available. I have full access to the machine, so installing libraries isn't a problem. Does anyone have any ideas how to do this? I've read that it's "difficult, but not impossible, to have support for both GIF and JPEG in one PHP installation", but how would I go about doing it?

Creating A Jpeg
what i need to do is to create a graphic file. the problem is that my hosting doesnt have the GD needed for all the graphic monipulation. so i need to build the file step by step.
as for building a BMP file, well that was a childs game, plain and simple. but as BMP file goes, its way too big. what i need is some way (algorithm mybe) to convert this bmp file data to a jpg file, or to create a jpg file to start from is also a possiblity.

now, i've dome some reading, and the jpeg stuff, something way out of my league, the calculations, the commpression, the 8 bit stuff. i was wondering if someone has a good and practical tutorial or documentation of steps (in the form of cookbook) to take in order to either convert a bmp data or create a jpg.

PHP With JPEG Support?
I seem to have a real problem in building PHP with JPEG support.

I've tried the following options to PHP's configure:
./configure --with-mysql=/usr/local/mysql/ --with-gd=../gd-1.8.4 --with-jpeg-dir=../pdflib-3.03 --with-apache=../apache_1.3.19 --enable-trackvars

After finishing the installation if I try to do any image function that needs JPEG support it get the error message: "No JPEG support in this PHP build". What am I missing here?

Reading JPEG Tag
I'm writing kind of a picture gallery and I would like to view information about each picture. So how do I read the JPEG tag in PHP? I been looking around the internet for a solution but haven't found any yet.

Help With Getting A Jpeg To Download On Mac IE
I have a link on a page that allows people to automatically download a jpeg.
The link basically goes to "download.jpg?pic=filename"

Here's what I have in my download.php file:

$pic=$_GET['pic'];
$file="lg/"."$pic";
$name="$pic";
$fp=fopen($file, "r");
header("content-disposition: filename="$name"");
header("content-type: attachment; name="$name"");
fpassthru($fp);
exit;

It works fine on everything I've tried on a PC, plus it works fine on Safari
and Netscape on a Mac, but it doesn't work on IE on a Mac, either on 9.x or
OS X.

Converting Gif To Jpeg
I cant seem to be able to output the output as a file which I can then move to "/directoryforjpegs/". Code:

PS Font
I have been trying to use .pfb fonts (Type 1) to generate dynamic
images. However the text in the images is very aliased and blurred.
This is of course not because of the font or the font style itself.
Please let me know if you have any ideas or opinions about it. Code
snippet:

$SIZE = 14;
$FONT_PATH = "/usr/X11R6/lib/X11/fonts/Type1/hell.pfb";
$FONT = ImagePSLoadFont($FONT_PATH);
$im = ImageCreate(100, 100);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 134, 134, 134);

// draw
ImagePSText($im, $str, $FONT, $SIZE, $gray, $gray, 0, $SIZE,0,0,0,16);
ImagePSFreeFont($FONT);

Can You Arc A Font With PHP?
I am writing a program with the GD library and need to arc a font like Photoshop does. I know how to write text, slant a font, etc., but I cannot figure out how to arc it and do other things. Is this possible with PHP?

Jpeg Is Outputted As Bitmap
I've created an image in PHP, PHP Code:

Show Jpeg From Sql Server
I am trying to show an jpeg image from a table in sql server and i really don't find any information about it. In sql server the jpeg is stocked in a field under the shape of bytes.

JPEG File Download Via PHP On Mac(IE)
I am trying to download a JPG file through a php page. The code is pretty straight forward, it obtains the filename from the query string, reads the file and outputs to the browser. Here is the code:

<?php
$filename = $_GET["file"];
$bytes = filesize("PATH_TO_FOLDER/$filename");
header("Content-type: application/jpg");
header("Content-disposition: attachment; filename="$filename"");
header("Content-length: $bytes");
//Read the file and output to browser
@readfile("PATH_TO_FOLDER/$filename");
//Code to record the download in database
?>

Originally I had "Content-type: image/jpeg"), but later on changed to "application/jpg" after reading through some forums on web. Both the content-types work fine in all browsers on a Windows PC, but they behave very differently with IE5.2 on MacOSX and IE5.1 on Mac OS9. The "Save As.." box does not open and the image gets displayed directly on the window. If I try to save the image by Ctrl+Click and Download to Disk, it shows the filename as "download.php" instead of the correct name "FILENAME.jpg" given in the Content-disposition header.

I did a lot of google and read in several forums that IE on Mac ignores the Content-disposition header. Is there any workaround for this. My aim is to display the "Save As.." dialog box on Mac IE (OSX and OS9), display the correct filename in the save as dialog box and allow the user to save the file through the dialog box.

(In Mozilla (Mac) it will download the file (but you have to be very quick as it tends to close the "What should Mozilla do with this file?" dialog quickly if you don't select the 'save' option and click 'ok'). Safari seems to be the only browser happy to download a .jpg file onto the disk.)

Php5, Gd & Jpeg Support
I have a problem:

I installed apache 1.3 on fedora core 3...
I also installed jpeg-6b, gd-2.0.28,
and I configured php5 with gd and jpeg support
--with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/lib

The gonfiguration hasn't errors:

checking for gdImageCreateFromJpeg in -lgd... (cached) yes

make, e make install, and I install php correctly.
But using phpinfo() I see that gd support is enabled, but not jpeg
support.

Grabs All The .gif And .jpeg Files
I wrote a script a little bit ago that grabs all the .gif and .jpeg files in a directory for an image gallery of sorts. I did it in php4. I just gave it to a friend of mine to use, but he only has php3 available to him and it's kicking up rough about !==.

Would someone please tell me how to rewrite this piece of code so it will work under php3.
while (false!==($file = readdir($handle))) {
I've only been coding since php4 and I have no real idea of the differences.

Extract Jpeg From A .avi File
im trying to find a way to grab a jpeg out of a .avi file so that when a user uploads a video file a thumbail is automatically generated. Ive got some c# code that does it off the command line but not much help for an online application.

Has anyone ever seen a script like this or point me in the right direction as im sturrguling to find any on the web.

With Includes / Font Tag
I was wondering how I would be able to strip the <font> tags from a file
when I include it so it can take on the characteristics of my own stylesheet
instead of the font tag attributes.

Font In GD Library?
Is it possible to select a font in the GD library?

PHP Font Boundingbox Help
I'm trying to understand how to work with bounding boxes around text with
the GD2 library. I thought I understood the concepts and wrote a simple
program to make sure. Here it is:

<?php
putenv('GDFONTPATH=c:windowsfonts');
$bbox=imagettfbbox(10,0,"arial.ttf","Hello World");
echo "upper left ($bbox[6],$bbox[7])-----upper right
($bbox[4],$bbox[5])<br><br>";
echo "lower left ($bbox[0],$bbox[1])-----lower right ($bbox[2],$bbox[3])";
?>

The idea is for me to find out the bounding box coordinates for a Hellow
World message. The output produced has me very confused though. It shows
the coordinates as follows:

upper left (-1,-10)-----upper right (66,-10)
lower left (-1,-1)-----lower right (66,-1)

I understand how the lower left coordinate can be -1,-1, and the lower right
coordinate seems logical, too.

How, though, can the upper coordinates have y values of -10? That's below
the baseline! It would seem logical that since I specified a font size of
10 my Y coordinates on the top would be roughly 10 more than the y
coordinates of the lower corners. So, I'd expect the upper coordinates to
be something like (-1,10) and (66,10). Where is the negative 10 coming
from?

Embed A Font
How do I embed a font onto a remote user's machine? Say he dont have a Papyrus but I want him to view the webpage using the Papyrus font.

How To Change Font In GD?
How can I change the font in GD?

Add A New Font To Editor
I want to add a new font to the editor(Innovaeditor).. I changed the font name in editor side and add that font in my fonts folder in control panel...
But the name of the font is like this "??"

How Do I Decrease JPEG File Size?
I'm using the JPEG image functions to create copies of JPEG files. The problem is the file size of the new files.
An example: A 65k jpg-file increases to 365k when I make a 1-to-1 copy (no resizing).

Is there a solution to this problem, except from decreasing image quality?

Resize JPEG And No EXIF Data
I try to use PEL (pel.sourceforge.net) to copy some exif information from
orginial camera jpeg to resized copy with php gd library. But without
success:(

1) File is uploaded to server with html upload form.

2) File is testes is it image/jpeg ?

3) If yes:

4) $copy = copy($_FILES['fotofile_'.$nrx]['tmp_name'],$destination_file);

5) if file height or width is too large - it's scaled:

$new_img = imagecreatetruecolor($new_x, $new_y);
$img = imagecreatefromjpeg($destination_file);
$org_x = imagesx($img);
$org_y = imagesy($img);
imagecopyresampled($new_img, $img,0, 0, 0, 0, $new_x, $new_y, $org_x,
$org_y);
imagejpeg($new_img, $destination_file.'_',$zcompression);
unlink(destination_file);
rename($destination_file.'_',$destination_file);
imagedestroy($new_img);
imagedestroy($img);

Now I've got smaller scaled new $destination_file. But it is without any
exif data now.
How to write a few exif information to it ? I need Camera Manufacturer,
Camera Model, Date&Time and ExposureTime, and ApertureFNumber

Of course I know how to read these informations before rescaling (I use
exif_read_data php function). But I cannot wirte them to new image ........

How To Resize A Jpeg-file Dynamically
I have to resize an uploaded file dynamically with php. can you tell me how I could do that?

Simple Upload And Save Jpeg
this is my first time trying to let folks upload a picture and save
it. I use a very basic html file input from

<form action="picact.php" method="post" enctype="multipart/form-data">
<input name="picture_name" type="file" id="picture_name">
<input type="submit" name="Submit" value="Submit">
</form>

In picact.php I try to run a simply copy function

if(!(copy($picture_name, "images/picupload.jpeg"))){
echo "trouble"; }
else {
echo "worked";}

it tells me it worked, but there is no file in the images folder, so I
don't know what is going wrong. does anyone have any advice?

I am using a static file name for now, to avoid any trouble with
variable names.

ImageString: How Do I Use A Font That Is Not One Of The Default 5?
I am playing with imagegd for generating images, and was wondering if there is a way I could use a font that is not one of the default 5? I remember reading somewhere about a TT font library for imagegd, but don't remember the specifics. If someone could point me in the right direction I would appreciate it.


Copyright © 2005-08 www.BigResource.com, All rights reserved