My Heroku app doesn't appear to want to recognize ANY kind of rmagick font family. In the following situation I would expect the font to be Times New Roman, but it is instead some system default. I've tried changing to Helvetica, and it's the same result - generic looking system font of some sort.
canvas = Magick::Image.read("caption:#{#statement.text}"){
self.size = "300x300"
self.colorspace = RGBColorspace
self.background_color = 'white'
self.font = "TimesNewRoman"
# self.font = "Helvetica"
self.gravity = CenterGravity
self.pointsize = 26
}.first
I've run identify -list font and observed that both TimesNewRoman and Helvetica are recognized by the system, but my image refuses to use them.
Bonus context: this is for the preview image in an og:image meta tag for display in Messages/Facebook Messager/etc. If I futz with the font family and display the image directly onto an html page there's no problem and it uses the appropriate font.
Per comment in the chain above:
Wowwwwwwwwww...apparently it's as easy as adding a .fonts folder to the root of your Heroku app and then moving your font into there - once you do that you can just reference the font directly when setting it onto ImageMagick...
So...yeah.
.fonts
| - "SF-Pro-Text-Light.otf
| - "SF-Pro-Text-Regular.otf
and
canvas = Magick::Image.read("caption:#{#statement.text}"){
self.size = "300x300"
self.colorspace = RGBColorspace
self.background_color = 'white'
self.font = "SF-Pro-Text-Light"
self.gravity = CenterGravity
self.pointsize = 26
}.first
Related
I want to print the captions imported from facebook/instagram in an image and save it. I want to do this using imagick library with php as I am creating the base image using imagick. The normal text prints properly but the emojis that are imported do not get printed as emoji's. Can anyone suggest how emojis can be printed using imagick.
What I have tried:
$eachpageimg = new Imagick ();
$eachpageimg->setResolution ( 300 , 300 );
$eachpageimg->newImage (1050, 1260 , 'rgb(255,255,255)');
$eachpageimg->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$eachpageimg->setImageFormat ('jpeg');
$eachpageimg->setImageCompressionQuality(100);
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'rgb(255, 255, 255)' );
$pixel->setColorValue(Imagick::COLOR_ALPHA, .8);
$draw->setStrokeColor('rgb(0,0,0)');
$draw->setFillColor ('rgb(0,0,0)');
$draw->setFont ("ROBOTO-REGULAR");
$draw->setFontSize (70);
$xpos = 10;
$ypos = 200;
$eachpageimg->annotateImage($draw, $xpos, $ypos, 0, "Gshdh😚😎😑😚🤠");
$filename = 'saved.jpg';
// SAVE FINAL page image
file_put_contents ($filename, $eachpageimg);
The font you are using needs to have the emojis in them. This can be checked by just editing a word or web page with that font set.
However:
"Gshdh😚😎😑😚🤠"
Those look very much like a mucked up character set rather than emoji. I strongly suspect that you are saving some data in a character set that doesn't support emoji (i.e. most non-UTF) character sets.
Exactly where that has happened will need to be something you discover yourself.
I have a Model that stores a FileReference. And now I want to create an Image with a Watermark in the Extbase Controller. Does anybody know where I have to look for? I only found solutions with typoscript.
I choosed the TypoScript way and it worked pretty well.
Fluid:
<f:cObject typoscriptObjectPath="lib.tx_myext.watermarkedImage" data="{imageUid:'{image.uid}',copyright:'{image.copyright}')}'}"/>
TypoScript:
lib.tx_myext.watermarkedImage = IMAGE
lib.tx_myext.watermarkedImage {
file = GIFBUILDER
file {
XY = [10.w],[10.h]
format = jpg
10 = IMAGE
10 {
file {
import.field = imageUid
treatIdAsReference = 1
width = 1162
height = 580c
}
}
20 = BOX
20 {
color = #FFFFFF
opacity = 70
dimensions = [10.w]-[30.w]-10,[10.h]-20,[30.w]+20,[30.h]+20
}
30 = TEXT
30 {
text.data = field:copyright
fontSize = 15
fontColor = #000000
fontFile = path/to/my/font.ttf
offset = [10.w]-[30.w]-5,[10.h]-5
}
}
}
The result is an image with a white box and the copyright text on it at the right bottom corner.
I think the easiest way will be to use a typoscript solution. This must not be as pure typoscript, but the datastructure of the typoscript might be needed as parameter to the core functions of the GifBuilder class. TYPO3 7.6 API
The GifBuilder class is inherited from the class GraphicalFunctions which can be used also, as there are only a few additions and the main functionality is here.
The last problem are the examples in the net according this task: they are pibased and all of them end up in something like
$img = $this->cObj->IMAGE($typoScriptArray);
in modern (namespaced) notation using current API this would be:
$gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GifBuilder::class);
$gifCreator->init();
$theImage='';
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
$gifCreator->start($fileArray, $typoScriptArray);
$theImage = $gifCreator->gifBuild();
}
Hello!
i'm trying to have my images appearing on a label by using this code
this is to save a random image from a particular URL
def photo_1():
urls = "https://www.flickr.com/photos/flickr/galleries/72157644537473411/" # You may change this into other websites!
regex = '<img src="([^"]+)".*>'
pattern = re.compile(regex)
photofile=urllib.urlopen(urls)
raw_data=photofile.read()
download=re.findall(pattern,raw_data)
randomdownload=random.choice(download)
urllib.urlretrieve(randomdownload, "1.gif")
global done_button2
done_button2 = Button(photo_window, text = 'Click here to display your chosen image on the black screen!', width = 53, command = generate_1)
done_button2.grid(row = 5, sticky = N)
done_button.config(state='disabled')
and this is to have the saved image appearing on a label but apparently not working so well ..
def generate_1():
img = ImageTk.PhotoImage(Image.open("1.gif"))
image_area = Label(photo_window, image = img, width = 55, height = 5).grid(row=2)
global done_button3
done_button3 = Button(photo_window, text = 'Click here to save the second random image locally! ', width = 53, command = photo_2)
done_button3.grid(row = 6, sticky = N)
done_button2.config(state='disabled')
this was a part of my code and when i run this application i made,
the only thing i can see is a white rectangular shape and i would like it to be as big as a black label underneath (size of (55,5) )with the actual image appearing...
can anyone help me with this problem?
You might have thought that my English is not that great haha
but please have mercy!
How can I use different system fonts for the line //pointsLabel.font = FontHUD, no custom font but different fonts available in the system
//"points" label
var pointsLabel = UILabel(frame: CGRectMake(ScreenWidth-340, 30, 140, 70))
pointsLabel.backgroundColor = UIColor.clearColor()
//pointsLabel.font = FontHUD
pointsLabel.text = " Points:"
self.addSubview(pointsLabel)
You could use UIFont.preferredFontForTextStyle(style: String) and pass any of the following as the style:
UIFontTextStyleHeadline
UIFontTextStyleSubheadline
UIFontTextStyleBody
UIFontTextStyleFootnote
UIFontTextStyleCaption1
UIFontTextStyleCaption2
On a bit of a side note - an advantage of using preferredFontForTextStyle is that you can use it to make your app support Dynamic Type because the size of the font returned varies depending on the user's preferred text size (set in the Settings app under Display & Brightness -> Text Size). To fully support dynamic type you should listen for changes in the preferred font size using NSNotifcationCenter and observing UIContentSizeCategoryDidChangeNotification, then updating your labels/textviews appropriately.
Why the tabbar doesn't load '#2x' image automatically on iPhone4 or 5?
Here is my code:
local function init()
--Create a group that contains the entire screen and tab bar
mainView = display.newGroup()
--Create a group that contains the screens beneath the tab bar
tabView = display.newGroup()
mainView:insert(tabView)
loadScreen("info-moregames")
tabBar = viewController.newTabBar{
background = "UI_INFO/tabBar.png", --tab bar background
default = {"UI_INFO/pogi_no.png","UI_INFO/noads_no.png","UI_INFO/share_no.png","UI_INFO/star_no.png","UI_INFO/restore_no.png","UI_INFO/back_no.png"},
over = {"UI_INFO/pogi_yes.png","UI_INFO/noads_yes.png","UI_INFO/share_yes.png","UI_INFO/star_yes.png","UI_INFO/restore_yes.png","UI_INFO/back_yes.png"},
tabs = {"More", "No Ads", "Share","Rate us","Restore","back"}, --names to appear under each tab icon
onRelease = showScreen --function to execute when pressed
}
mainView:insert(tabBar)
tabBar.selected()
return true
end
If you have a config.lua file like above, your images will be automaticaly scaled.
application = {
content = {
width = ***,
height = ***,
scale = "letterBox",
}
If you have a config.lua file like above, you can use different images for different resolutions. Note that, you should have two images for that. For example, you have an image temp.png which is 20x20. Then you should have another temp#2x.png which is 40x40. In this way you can get better images with better resolution. And also, 1.5 value means that if the device's screen is 1.5 times more then your desired resolution, use images with #2x ending.
application = {
content = {
width = ***,
height = ***,
scale = "letterBox",
imageSuffix = {
["#2x"] = 1.5,
}
},
}