English 中文(简体)
利用图象Magick与老年家庭进行对比
原标题:Specifying a font with the font family using ImageMagick

能否在图像Magick使用老家 f?

我已尝试过我能够想到的一切,似乎没有任何工作。 我做了很多的搜索,我似乎找不到任何事情来处理这一具体问题。

我最终使用购买力平价,但我也尝试在指挥线上使用图像Magick,但没有成功。 我正在使用图象6.7.6。 在这方面,我迄今为止做了些什么。

  • I have tested the fonts that ImageMagick reckognizes using the identify -list font command
  • I have manually created a type.xml file based on the xml files that came installed on my system
  • I have created a type.xml file using this script: imagick_type_gen
  • I have tested with multiple font types: ttf, otf, pfb, ttc

下面是某些字体的<代码>识别-list font的样本输出。 我测试了:

Font: DejaVu-Sans-Book
  family: DejaVu Sans
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/dejavu/DejaVuSans.ttf

Font: Baskerville-Regular
  family: Baskerville
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/custom/Baskerville.ttc

Font: Palatino-Roman
  family: Palatino
  style: Normal
  stretch: Normal
  weight: 400
  glyphs: /usr/share/fonts/urw-fonts/p052003l.pfb

Font: Honey-Script-Light
  family: Honey Script
  style: Normal
  stretch: Normal
  weight: 300
  glyphs: /usr/share/fonts/custom/HoneyScript-Light.ttf


If I specify the full font name everything works as expected:

convert -pointsize 32 -font "Honey-Script-Light" label: Testing  testing.png

“Working”/


However, when I try to use the font family (both listed by identify -list font and listed in type.xml) I get the default system font:

convert -pointsize 32 -family "Honey Script" label: Testing  testing.png

“Not


I have also tried specifying all of the font s parameters and it again does not work:

convert -pointsize 32 -stretch Normal -style Normal -weight 300 -family "Honey Script"   label: Testing  testing.png



When I do a similar process through PHP, it actually returns an error as soon as I try to set the font family of the draw object.

$draw->setFontFamily( Honey Script );

出现这一错误:

PHP Fatal error:  Uncaught exception  ImagickDrawException  with message  Unable to set font family; parameter not found in the list of configured fonts



Just like the command line option, if I specify the full font name, the image is rendered properly.

$draw->setFont( Honey-Script-Light );



From everything I have found about how to configure a font to be used with ImageMagick, the fonts are indeed configured. Why can t I select the fonts based on the font family?

Is this possibly an undocumented bug? Is there something I am missing?

我认识到,我可以简单地说明全方位的名声,并且可以这样做,但我的项目有一个具体理由,使更能具体地说明老家。

如果自己不工作,为什么要具体指明老年家庭? 这正是Magick在老年家庭选择方面所说的:

This setting suggests a font family that ImageMagick should try to use for rendering text. If the family can be found it is used; if not, a default font (e.g., "Arial") or a family known to be similar is substituted (e.g., "Courier" might be used if "System" is requested but not found).

任何想法都受到欢迎。 此时此刻,我非常 st。


EDIT:
The main reason I would prefer to use font families rather than fully named fonts is because of the input I am processing. I receive files from a third party that need to be processed. These files specify fonts as:

font-family="Honey Script" font-style="Normal" font-stretch="Normal" font-weight="300"

如果我不得不根据这一信息具体说明确切的名词,那么我就需要为真实姓名的亲子家庭和属性的各种可能组合绘制一份地图。 由于该系统增加了数百个字体,因此很难维持。

在我看来,必须有一种办法,根据上文所列有关字体的所有现有细节,使图像Magick能够检索准确的字体。

如果无法做到这一点,那么,为什么成像会有什么选择来具体指明老年家庭?

问题回答

Here is method that outputs as image(into browser) all available Imagick fonts

 public function test_fonts(){
    //load background
    $im = new Imagick();
    $im->newimage(800, 10000,  lightgray );
    $y = 10;
    $i = 1;
    foreach($im->queryFonts() as $font){
        $insert_image = new Imagick();
        $insert_image->newImage(600, 30,  whitesmoke );
        $insert_image->setImageFormat("png");
        $draw = new ImagickDraw();
        $draw->setFont($font);
        $draw->setFontSize(25);
        $draw->setFillColor(new ImagickPixel( black ));
        $draw->setgravity(imagick::GRAVITY_NORTH);
        $insert_image->annotateImage($draw, 0, 0, 0, $i .  .  .  $font );
        $im->compositeImage( $insert_image,  $insert_image->getImageCompose(),100, $y);
        $y += 30;
        $i++;
    }
    $im->setImageFormat( jpg );
    header( Content-Type: image/jpg );
    echo $im;

}

You should see something like this: enter image description here

这是因为家庭如何工作;例如,“Arial”的老年家庭包含对 bold、斜体、 underlines等的具体字体定义。 你在选择使用你的图像时必须具体。

I m guessing that if you really wanted to, you could do the following:

  1. Take the font family name, replace spaces with dashes
  2. If that works, great!
  3. If not, append -Regular to the end and try again

但是,除非你再次被迫这样做,否则你会做任何与老年家庭有关的方案;

My source of imagick knowledge mostly comes from this guy: http://valokuva.org/?cat=1





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签